1

I'm tring to set the log names to this pattern: ApplicationName.Date.log

This my config file code:

<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>

The problem is that at midnight, the file becomes corrupted like this:

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  

What I wanted is:

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  

Any advice will be welcome.

4

1 回答 1

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.

于 2013-06-14T07:00:28.623 回答