logging - log4net配置异常

标签 logging web-config log4net configsection

我正在使用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'. 


编辑:尝试了毛里西奥·舍弗(M​​auricio 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" />

最佳答案

如果您的配置位于单独的log4net.config文件中,则不需要sectionHandler。去掉它。

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

另请参见this question

关于logging - log4net配置异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1930083/

相关文章:

python - 如何禁用特定模块的日志记录

logging - Azure跟踪日志在模拟器上工作但在云上不工作

asp.net - 潜在危险值,错误不会消失

c# maxreceivedmessagesize 不工作

Log4Net 不工作

c# - Ninject.Extensions.Logging.Log4Net 为类/方法名称生成不正确的输出

log4net - 如何为每个附加程序定义不同的记录器级别

c - 记录对文件的函数调用并将此日志文件用作程序代码

在 C 中从对数转换为线性并取平均值

asp.net-mvc - 配置托管模块的 Asp.net MVC 错误