【问题标题】:log4net configuration exceptionlog4net 配置异常
【发布时间】:2010-12-28 03:43:51
【问题描述】:

我正在使用 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" />

【问题讨论】:

  • 编辑:我刚刚发现我的 web.config 有一个类型“Log4NetConfigurationSectionHlandler”来自 web.config。我仍在努力使用外部配置文件完成这项工作

标签: logging web-config log4net configsection


【解决方案1】:

如果您将配置放在单独的 log4net.config 文件中,则不需要 sectionHandler。删除它。

您也可能在代码中的某处调用XmlConfigurator.Configure()。也将其删除。

另见this question

【讨论】:

  • 我支持这个回复。当我的 app.config 文件中有 log4net 部分时,我在 WPF 应用程序中遇到了同样的问题。我将配置移至单独的 log4net.config 文件,它解决了问题。
  • 我在尝试这个建议时遇到了这个错误:log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file。检查 .config 文件中的 元素。配置部分应如下所示:
  • @ram:您可能在代码中的某处调用了 XmlConfigurator.Configure()。删除它。
  • 我有点迷失了 mauricio,我在初始化我的日志管理器时调用它 static ActivityLogManager() { log4net.Config.XmlConfigurator.Configure();它不应该被调用?
  • 没错,你应该调用它。程序集属性已经处理了初始化。
猜你喜欢
  • 1970-01-01
  • 2014-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多