开发者

In log4net, how can I call Config.XmlConfigurator only once for a solution?

I'm just getting started with log4net. To read the XML configuration file, it is my understanding that you have to place the following in the AssemblyInfo file of your project:

<Assembly: log4net.Config.XmlConfigurator(ConfigFile:="Log4net.Config", Watch:=True)> 

I have a solution with 开发者_如何学JAVAseveral projects, and it seems that I have to put this statement in every AssemblyInfo file in the solution (one for each project). I tried just putting the statement in the Startup project's AssemblyInfo, but logging calls in other projects won't work. I have to include the statement in every project that makes logging calls.

1) Is there a way to make the call to Config.XmlConfigurator in one place, one time for an entire solution?

2) What causes the behavior I'm seeing?


You should place this in the assembly who "host" your solution. In a console/winform/wpf application in the assembly who compile to the ".exe", in a web application I usually call explicitly XmlConfigurator.Configure(); in the Application-Start event.


Why not to use static constructor in class that will be referenced by all assemblies? If they are in single app domain than it will be called exactly once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜