log4net,这个配置是什么

时间:2012-01-20 10:33:10

标签: log4net log4net-configuration

log4net正在报告:

  

找不到logger log4net的appender:Logger:请   正确初始化log4net系统。

我有一个独立的log4net配置文件:

<!--?xml version="1.0"?-->
<configuration>
  <configsections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" />
  </configsections>
  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="c:\temp\log.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="5MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>


  </log4net>
</configuration>

..和这个应用程序启动代码

private static ILog logger;
protected void Application_Start(object sender, EventArgs e)
{
    ////This tells log4net where to go and look for its configuration file and also to watch it for any changes
    log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(@"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Config\Moogle\Log4Net.config"));
    logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
    logger.Debug("Application_Start Fired");

1 个答案:

答案 0 :(得分:20)

您只定义了一个appender。您还需要定义根记录器和记录器以使用appender(如果只需要一个,它们可以是相同的记录器)。将以下根元素添加到log4net配置中。

<root>
  <level value="DEBUG" />
  <appender-ref ref="RollingLogFileAppender" />
</root>