Log4Net RollingFileAppender with composite rolling style is overwritting data

本小妞迷上赌 提交于 2019-12-04 03:29:39
dommer

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>

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

Eddie

Try adding the maxSizeRollBackups parameter in your RollingFileAppender to solve half of our problem. This way, when the log file rolls, it won't overwrite your old log, but will roll it to another file.

<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"/>
  <param name="maxSizeRollBackups" value="10" />
  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="%m%n"/>
  </layout>
</appender>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!