I am using log4net in an application with a RollingFileAppender. I have the rollingStyle set to "Composite" and staticLogFileName to "false" but when the maximumFileSize is reached it overwrites the current file rather than appending a 1 to the end. Below is my config code:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<root>
<level value="INFO" />
<appender-ref ref="console" />
<appender-ref ref="RollingFileAppender"/>
</root>
<appender name="console" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %logger - %message%newline" />
</layout>
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs\" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<datePattern value="yyyyMMdd'.log'" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maximumFileSize value="10KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
The date part works correctly when the day rolls over but i cant work out why the file size does not. Please note the 10kb size is only to test the functionality and in production will be a greater size.
Can anyone help?
Thanks
You haven’t configured maxSizeRollBackups, by default it is 0, so there will be no backup files and the log file will be truncated when it reaches maximumFileSize
.
Configure as
<maxSizeRollBackups value="10" />
Note that a value of 10 in combination with the yyyyMMdd
DatePattern
will keep 10 files per day.