2

我的 App.config 如下所示。该文件与调用相同的项目:

log4net.Config.XmlConfigurator.Configure();
private static log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

但是我收到:

Log4net:错误 XmlConfigurator 未能在应用程序的 .config 文件中找到配置部分“log4net”。检查 .config 文件中的<log4net>and<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>
4

1 回答 1

6

我在您的 web.config 中立即看到的唯一内容是您缺少结束标记。

于 2010-07-20T18:06:48.330 回答