Now Log4Net.config isn't being loaded as I moved my wrapper class to its own class project

爱⌒轻易说出口 提交于 2019-12-13 03:31:30

问题


Can anyone help, i have been using log4net with success i basically had a static class (wrapper) in my webproject and i load my config from external file called log4net.config by adding this in assemblyinfo.cs

    // log4net config file
    [assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]

All good!, now i decided to move my static class to its own class project so i can share my static class (wrapper) with other projects.

The log4net.config is still in the webproject but of course its not getting loaded now, I can tell this because in my static class (now its own project) i am doing

          return LogManager.GetLogger("InfoLogger").IsInfoEnabled;

and IsInfoEnabled returns false, and nothing is being logged, the .config file is not being read...

Remembering the Log4net wrapper (static class) is in its own class project but the .config file is in the web project ihave.. I need it like this because .config can change on a project by project basis but generally the wrapper won't.

Of course i thought i will create an abstract class and just inherit in my webproject and override anything if i need to ... BUT of course you can't inherit static classes or even make abstract..

I am sure someone else has come across this, any ideas? .. any help really appreciated


回答1:


You need to put the XmlConfigurator assembly attribute in the class library that wraps log4net. You can keep your log4net.config file in the root directory of your web application.

The XmlConfigurator assembly attribute is read the first time log4net is initialized. Log4net scans the calling assembly to find the attribute.



来源:https://stackoverflow.com/questions/1347429/now-log4net-config-isnt-being-loaded-as-i-moved-my-wrapper-class-to-its-own-cla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!