RollingFileAppender是覆盖文件且未在末尾附加数

RollingFileAppender是覆盖文件且未在末尾附加数

本文介绍了Log4net RollingFileAppender是覆盖文件且未在末尾附加数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在具有RollingFileAppender的应用程序中使用log4net.我将rollingStyle设置为"Composite",并将staticLogFileName设置为"false",但是当达到maximumFileSize时,它将覆盖当前文件,而不是在末尾附加1.下面是我的配置代码:

I am using log4net in an application with a RollingFileAppender. I have the rollingStyle set to "Composite" and staticLogFileName to "false" but when the maximumFileSize is reached it overwrites the current file rather than appending a 1 to the end. Below is my config code:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <root>
    <level value="INFO" />
    <appender-ref ref="console" />
    <appender-ref ref="RollingFileAppender"/>
  </root>
  <appender name="console" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %level %logger - %message%newline" />
    </layout>
  </appender>
  <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="logs\" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
    <datePattern value="yyyyMMdd'.log'" />
    <staticLogFileName value="false" />
    <appendToFile value="true" />
    <rollingStyle value="Composite" />
    <maximumFileSize value="10KB" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %level %logger - %message%newline" />
    </layout>
  </appender>
</log4net>

当一天过去时,日期部分可以正常工作,但是我无法弄清为什么文件大小不正确.请注意,10kb的大小仅用于测试功能,在生产中会更大.

The date part works correctly when the day rolls over but i cant work out why the file size does not. Please note the 10kb size is only to test the functionality and in production will be a greater size.

任何人都可以帮忙吗?

谢谢

推荐答案

您尚未配置 maxSizeRollBackups ,默认值为0,因此将没有备份文件,并且到达maximumFileSize时日志文件将被截断.

You haven’t configured maxSizeRollBackups, by default it is 0, so there will be no backup files and the log file will be truncated when it reaches maximumFileSize.

配置为

<maxSizeRollBackups value="10" />

请注意,如果将yyyyMMdd DatePattern与10结合使用,则每天将保留10个文件.

Note that a value of 10 in combination with the yyyyMMdd DatePattern will keep 10 files per day.

这篇关于Log4net RollingFileAppender是覆盖文件且未在末尾附加数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:42