log4net配置异常 [英] log4net configuration exception
问题描述
我正在使用log4net进行日志记录.我的日志记录配置存储在单独的文件中.
I am using log4net for logging. My logging configuration is stored in a separate file.
Web.Config:ConfigSections
Web.Config:ConfigSections
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
在AssemblyInfo.cs中指定我的配置文件
Specifying my config file in AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(ConfigFile="Log4Net.config", Watch = true)]
当我初始化LogManager时,出现此错误
And when I initialize my LogManager, I get this error
"System.TypeLoadException"
message: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'.
是的,它说的是"Log4NetConfigurationSectionHlandler",不是错字
Yes it says "Log4NetConfigurationSectionHlandler'", it is not a typo
以及以后的错误
An error occurred creating the configuration section handler for log4net: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'.
尝试了毛里西奥·谢弗(Mauricio Scheffer)的建议
Tried Mauricio Scheffer's suggestion
得到
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" />
推荐答案
如果您的配置位于单独的log4net.config文件中,则不需要sectionHandler.删除它.
If you have your config in a separate log4net.config file you don't need the sectionHandler. Remove it.
您可能还会调用 XmlConfigurator.Configure ()在您代码中的某个位置.也将其删除.
You're also probably calling XmlConfigurator.Configure() somewhere in your code. Remove that as well.
另请参见此问题
这篇关于log4net配置异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!