本文介绍了具有复合滚动样式的Log4Net RollingFileAppender将覆盖数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置为的Log4Net RollingFileAppender:

I have a Log4Net RollingFileAppender that is configured as:

<configuration>

  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>

  <log4net>

    <root>
      <level value="ALL" />
    </root>

    <logger name="RollingFileAppender" additivity="false">
      <level value="DEBUG"/>
      <appender-ref ref="RollingFileAppender" />
    </logger>

    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender" >
      <param name="File" value="C:\\MyLog.log" />
      <param name="AppendToFile" value="true" />
      <param name="DatePattern" value="yyyy-MM-dd"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%m%n"/>
      </layout>
    </appender>

  </log4net>

</configuration>

查看文档默认滚动样式为合成" ,因此有意义的是它将在达到特定大小(默认为10MB)时滚动,而不仅仅是在日期上滚动.

Looking at the documentation, the The default rolling style is Composite, so it makes sense this will roll when it reaches a certain size (the default of 10MB), not just on the date.

问题是当它达到大小时,它正在重新启动日志,而我从前半天开始丢失数据(它在中午左右达到此大小).
为什么不将其滚动到一个新文件并将所有以后的日志行都放入MyLog.log?还是正在滚动日志,但是在午夜之后,它又在滚动并且覆盖了已过时的日志(例如,达到10MB后又滚动到MyLog.log2009-04-08,然后在午夜之前覆盖了同一文件)?

The problem is when it hits the size, it is restarting the log and I am losing the data from the first half of the day (it reaches this size around noon).
Why wouldn't this just roll to a new file and all future log lines are put into the MyLog.log?Or is it the log is rolling, but then at midnight, it is rolling again and overwritting the dated log (eg. rolling to MyLog.log2009-04-08 once it reaches 10MB, and then overwritting this same file at midnight)?

我将设置

<rollingStyle value="Date" />

这是我要做的全部工作,以确保它只在日期"边界上滚动吗?我可以在Log4Net.config中即时更改此设置,还是必须重新启动应用程序?它正在IIS6上运行.

Is this all I have to do to ensure it only rolls on the Date boundary? Can I change this on the fly in the Log4Net.config, or do I have to restart the application? It is running on IIS6.

推荐答案

这是我的设置.它仅在日期滚动:

Here's my settings. It rolls only on date:

<log4net>
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
        <file value="c:\Logs\Today.log"/>
        <rollingStyle value="Date"/>
        <datePattern value="yyyyMMdd"/>
        <appendToFile value="true"/>
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%level %logger %date{ISO8601} - %message%newline"/>
        </layout>
    </appender>
    <root>
        <!-- Options are "ALL", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" and "OFF". -->
        <level value="ERROR"/>
        <appender-ref ref="RollingFile"/>
    </root>
</log4net>

更改为web.config,将自动重新启动应用程序(因此您将丢失会话等).

Changes to your web.config, will restart the application automatically (so you'll lose sessions, etc).

这篇关于具有复合滚动样式的Log4Net RollingFileAppender将覆盖数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:42
查看更多