Log4Net separate config file not working

限于喜欢 提交于 2019-12-03 13:03:03

I had to setup the config file watcher in Application_Start:

log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + "logging.config"));

Turns out that DotNetOpenAuth.Core.dll uses log4net and will make using the AssemblyInfo solution not work. I found the details in this blog: http://hanskindberg.wordpress.com/2013/04/07/log4net-configuration/ (look at the paragraph that mentions DotNetOpenAuth.Core.dll)

I struggled for this solution for many days. I could finally found below solution worked for me>

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)] plus the configuration suggested by @BCarlson

XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));

To summaries everything, I have created a sample c# console project for log4net configuration with external log4net.config file. https://github.com/riddhik84/Log4net-Tutorial

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