整个午夜的log4net滚动文件appender

时间:2013-06-13 20:37:28

标签: log4net log4net-appender

我要将日志名称设置为此模式: ApplicationName.Date.log

这是我的配置文件代码:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="Client.%date{dd-MM-yyyy}.log" type="log4net.Util.PatternString"/>
  <appendToFile value="true"/>
  <rollingStyle value="composite"/>
  <datePattern value="dd-MM-yyyy"/>
  <maxSizeRollBackups value="-1"/>
  <maximumFileSize value="50MB"/>
  <PreserveLogFileNameExtension value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date %-2level %logger - %message%newline"/>
  </layout>
</appender>

问题是在午夜,文件被损坏如下:

Client.13-06-2013.log  
Client.13-06-2013.1.log  
Client.13-06-201313-06-2013.1.log  
Client.13-06-201313-06-2013.2.log  
Client.13-06-201313-06-2013.log  

我想要的是:

Client.13-06-2013.log
Client.13-06-2013.1.log  
Client.13-06-2013.2.log  
Client.14-06-2013.1.log  
Client.14-06-2013.log  

欢迎任何建议。

1 个答案:

答案 0 :(得分:0)

我想出来了,这里是代码:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="Client.log" type="log4net.Util.PatternString" />
  <appendToFile value="true" />
  <rollingStyle value="composite" />
  <datePattern value=".dd-MM-yy" />
  <maxSizeRollBackups value="-1" />
  <maximumFileSize value="50MB" />
  <staticLogFileName value="false" />
  <PreserveLogFileNameExtension value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date %-2level %logger - %message%newline" />
  </layout>
</appender>

我已从%date媒体资源中删除了file 并添加了staticLogFileName属性,将其设置为false