log4net configuration exception

雨燕双飞 提交于 2019-12-05 12:51:39

问题


I am using log4net for logging. My logging configuration is stored in a separate file.

Web.Config:ConfigSections

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

Specifying my config file in AssemblyInfo.cs

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

And when I initialize my LogManager, I get this error

"System.TypeLoadException"
message: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'.

Yes it says "Log4NetConfigurationSectionHlandler'", it is not a typo

and later, this error

An error occurred creating the configuration section handler for log4net: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'. 

Edit: Tried Mauricio Scheffer's suggestion

got

log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

回答1:


If you have your config in a separate log4net.config file you don't need the sectionHandler. Remove it.

You're also probably calling XmlConfigurator.Configure() somewhere in your code. Remove that as well.

Also see this question



来源:https://stackoverflow.com/questions/1930083/log4net-configuration-exception

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