log4net配置异常

发布于 2024-08-14 19:54:32 字数 1237 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回心转意 2024-08-21 19:54:33

如果您的配置位于单独的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文