当rollingstyle设置为date时,有时log4net不会滚动日志文件 [英] log4net does not roll over the log file sometimes when rollingstyle set to date

查看:80
本文介绍了当rollingstyle设置为date时,有时log4net不会滚动日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows C#应用程序,该应用程序使用log4net进行日志记录.记录器的配置方式如下:

I have a Windows C# application which uses log4net for logging. This is how the loggers are configured:

 <log4net>
    <appender name="DebugFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="Local\logs\ApplnTrace.log" />
      <threshold value="INFO" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%5p] - (%file:%line) %m%n" />
      </layout>
    </appender>
    <appender name="MSGFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value=".\local\logs\MsgTrace.log" />
      <threshold value="INFO" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d %n%m%n" />
      </layout>
    </appender>
    <logger name="ApplnLogger">
      <appender-ref ref="DebugFileAppender" />
    </logger>
    <logger name="MsgLogger">
      <appender-ref ref="MSGFileAppender" />
    </logger>
 </log4net>

文件有时会根据日期进行滚动,有时甚至不会,并且当文件未滚动时,日志记录也会停止.有人可以帮我找出原因吗?

The files are rolled over based on date sometimes and sometimes does not and when files are not rolled over, the logging also stops. Can anybody help me find out why?

推荐答案

log4Net旨在悄无声息地失败.当事情停止工作时,通常会出现问题(最常见的是配置问题或文件系统安全问题).

log4Net is designed to fail quietly. When things stop working, there's usually a problem (most often, it's a config issue or a filesystem security issue).

您可能想尝试启用内部lo​​g4net调试.将此密钥停放在app.config的< appSettings> 元素中:

You might want to try enabling internal log4net debugging. Park this key in the <appSettings> element of your app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="log4net.Internal.Debug" value="true"/>
  </appSettings>
</configuration>

然后启动您的应用.Log4net将产生大量调试信息.它被写入System.Console和System.Diagnostics.Trace系统.您可以从附加的调试器中捕获跟踪消息,也可以在app.config文件中添加跟踪侦听器.如果跟踪侦听器写入文件,请确保您的进程具有写访问权,否则您将看不到任何内容:

then start your app. Log4net will spew a bunch of debugging info. It gets written to System.Console and to the System.Diagnostics.Trace system. You can catch the trace messages from an attached debugger or by adding a trace listener in the app.config file. If the trace listener writes to a file, make sure that your process has write access, otherwise you'll see nothing:

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

不同的跟踪侦听器数量您可以在此处进行连线,包括写入Windows事件系统的内容.

There are a number of different trace listeners you can wire up here, including ones that write to the windows event system.

更多信息在这里:

这篇关于当rollingstyle设置为date时,有时log4net不会滚动日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆