Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net RollingFileAppender Size rollingStyle file extension

Tags:

I am using the RollingFileAppender and the Size rollingStyle. By default it creates backup files with a numbered extension, this drives me nuts. Is it possible to change it so it always uses a defined extension (say .txt or .log) and inserts the number as part of the file name?

For example:

myapp.log
myapp.1.log
myapp.2.log
myapp.3.log

Here is my current configuration:

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">     <file value="myapp.log"/>     <appendToFile value="true"/>     <rollingStyle value="Size"/>     <maximumFileSize value="1MB"/>     <maxSizeRollBackups value="10"/>     <staticLogFileName value="true"/>     <layout type="log4net.Layout.PatternLayout">         <conversionPattern value="%date{ISO8601} [%3thread] %-5level %logger{3}: %message%newline" />     </layout> </appender> 
like image 424
BrettRobi Avatar asked Apr 09 '10 15:04

BrettRobi


People also ask

What is RollingFileAppender in log4net?

RollingFileAppender means the system creates a log file based on your filters, this way you can have log files based on dates (one file each day), or get the file splitted into small chunks when it hits certain size.

What is Maxsizerollbackups?

Gets or sets the maximum number of backup files that are kept before the oldest is erased.


1 Answers

The PreserveLogFileNameExtension property set to true should do the trick. Note: this property is not available in the currently released version 1.2.10 but is part of the current source. If you grab and build the source you're good to go.

Update: it is great to see log4net is moving forward. Version 1.2.11, and with it the PreserveLogFileNameExtension property, have been released.

like image 125
Peter Lillevold Avatar answered Sep 24 '22 20:09

Peter Lillevold