bea*_*ito 2 c# logging log4net log4net-configuration
我的App.config如下.该文件与调用的项目相同:
log4net.Config.XmlConfigurator.Configure();
private static log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Run Code Online (Sandbox Code Playgroud)
但是我收到了:
Log4net:ERROR XmlConfigurator无法在应用程序的.config文件中找到配置节'log4net'.检查.config文件中的
<log4net>和<configSections>元素.配置部分应如下所示:<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /
因为我刚开始使用log4net,我觉得我犯了一个愚蠢的错误.对此有何帮助?
<!-- language: xml -->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\log-file.txt" />
<appendToFile value="true"/>
<rollingStyle value="Size" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<maxSizeRollBackups value="10" />
<conversionPattern value="%date [%thread] %-5level %location %logger - %message%newline" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
</configuration>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7661 次 |
| 最近记录: |