log4net配置异常
我正在使用 log4net 进行日志记录。我的日志记录配置存储在一个单独的文件中。
Web.Config:ConfigSections
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
在 AssemblyInfo.cs 中指定我的配置文件
[assembly: log4net.Config.XmlConfigurator(ConfigFile="Log4Net.config", Watch = true)]
当我初始化 LogManager 时,出现此错误
"System.TypeLoadException"
message: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'.
是的,它显示“Log4NetConfigurationSectionHlandler”,这不是拼写错误
,后来
An error occurred creating the configuration section handler for log4net: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'.
此错误编辑:尝试了 Mauricio Scheffer 的建议
出现
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" />
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" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的配置位于单独的 log4net.config 文件中,则不需要sectionHandler。将其删除。
您也可能正在调用 XmlConfigurator.Configure()< /a> 代码中的某处。也将其删除。
另请参阅此问题
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