Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hi
 
I am trying to configure the log4net rolling file appender, so it would create a new log every minute. Below is my configuration.
 

<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value="Logs/Log_%date{dd.MM.yyyy-HH.mm}.log" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <maxSizeRollBackups value="6" />
      <datePattern value="yyyyMMdd-HHmm" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date{HH:mm:ss,fff}, %message%newline" />
      </layout>
    </appender>
 
With this configuration I get a new log every minute which is OK. The only problem is the name of the logs. The file name of the first log is as expected: Log_12.05.2013-01.43.log .
The problem is with the consecutive log files.
The next one is not named Log_12.05.2013-01.44.log as expected but
Log_12.05.2013-01.43.log20130512-0143
 
It seems I found a partial solution to my problem. The problem was with the "value" attribute of the file element, and the missing "preserveLogFileNameExtension" element.
Below is the updated configuration
 
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value="Logs/Log_.log" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd-HHmm" />
      <maxSizeRollBackups value="6" />
      <preserveLogFileNameExtension value="true"/>
      <staticLogFileName value="false" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date{HH:mm:ss,fff}, %message%newline" />
      </layout>
    </appender>
 
But with the new configuration there is another problem. It seems that the "maxSizeRollBackups" element has no effect - the log4net is not deleting the old logs.
 
Uroš
Posted 11-May-13 14:55pm
koleraba1.2K
Edited 11-May-13 15:32pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

It seems that maxSizeRollBackups is not supported when rolling by date. For more information or if anybody needs that functionality follow this http://stackoverflow.com/questions/2290552/log4net-remove-old-files-rolling-by-date[^] link
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 235
1 DamithSL 225
2 OriginalGriff 198
3 George Jonsson 170
4 Maciej Los 165
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100