log4net没有从IIS登录到事件查看器

时间:2015-04-23 18:55:46

标签: asp.net iis log4net

我在IIS中设置了一个Web服务,记录到文本文件的appender工作正常(文本文件与运行Web服务的目录位于同一目录中)。写入事件查看器的追加器不起作用,我当前以管理员身份连接到Web服务,所以理论上我应该能够做到这一点,我还应该检查/查看我是否还有其他事情&#39我失踪了?

log4net.config:

             

<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date{ABSOLUTE} [%thread] %level %logger - %message%newlineExtra Info: %property{testProperty}%newline%exception"/>
  </layout>
  <filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="INFO"/>
    <levelMax value="FATAL"/>
  </filter>
</appender>

<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
  <param name="ApplicationName" value="Lending Service" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message %newline %exception"  />
  </layout>
  <filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="INFO"/>
    <levelMax value="FATAL"/>
  </filter> 
</appender>

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">

  <threshold value="DEBUG"/> 
  <file value="webLog.log"/>
  <appendToFile value="true"/>
  <rollingStyle value="Size"/>
  <maxSizeRollBackups value="5"/>
  <maximumFileSize value="10MB"/>
  <staticLogFileName value="true"/>

  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %level %logger - %message%newline%exception"/>
  </layout>

</appender>


<root>
  <appender-ref ref="RollingFileAppender"/>
  <appender-ref ref="EventLogAppender" />
</root>

<logger name="LendingService.Global_asax">
  <appender-ref ref="RollingFileAppender"/>
  <appender-ref ref="EventLogAppender" />
</logger>

<logger name="LendingService.LendingService">
  <appender-ref ref="RollingFileAppender"/>
  <appender-ref ref="EventLogAppender" />    
</logger>  

</log4net>
<startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

1 个答案:

答案 0 :(得分:2)

找出出错的最佳方法是启用log4net内部调试,这将告诉你log4net失败的地方:

<configuration>
...
    <appSettings>
        <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>

...

    <system.diagnostics>
        <trace autoflush="true">
            <listeners>
                <add 
                    name="textWriterTraceListener" 
                    type="System.Diagnostics.TextWriterTraceListener" 
                    initializeData="C:\tmp\log4net.txt" />
            </listeners>
        </trace>
    </system.diagnostics>
</configuration>

Log4net FAQ