tags:

views:

644

answers:

1

INTENT:

a) I want my logs to be rolled by date in following file format yyyy-MM-dd.txt.

b) Additionally to this I want to remove old files which are out of maxSizeRollBackups range.

CAUTION A maximum number of backup files when rolling on date/time 
  boundaries is not supported. [RollingFileAppender spec][1]

SOLUTION

for a) is enough to do the configuration

<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="logs\" />
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <maxSizeRollBackups value="30" />
  <datePattern value="yyyy-MM-dd'.txt'" />
  <staticLogFileName value="false" />
  <layout type="log4net.Layout.XmlLayoutSchemaLog4j"/>
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
</appender>

for b) Is the inheritance from RollingFileAppender + delete stuff the only way to achieve this ?

+5  A: 

I spent some time looking into this a few months ago. v1.2.10 doesn't support deleting older log files based on rolling by date. It is on the task list for the next release. I took the source code and added the functionality myself, and posted it for others if they are interested. The issue and the patch can be found at https://issues.apache.org/jira/browse/LOG4NET-27 .

Mafu Josh