We have an application with the following log4net configuration (v 2.0.12):
<appender name="LogFileAppenderXML" type="log4net.Appender.RollingFileAppender">
<file value="D:\Logs\" />
<datePattern value="yyyy-MM-dd'_AppName.xml'" />
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="30" />
<maximumFileSize value="500KB" /> <-- in production this value is much larger; 500KB produces rolled-over files faster when reproducing this behavior
<staticLogFileName value="false" />
<layout type="log4net.Layout.XmlLayout"/>
</appender>
This means we want to roll over both by date (day) and by size (i.e. rollingStyle=Composite). We also want to keep the filename of the logfile being actively logged to fixed (staticLogFileName) so that we can keep the file open with a viewer (Log4View). Everything works as expected within a single run of the application. But if I restart the application, the already rolled-over files are overwritten.
Assume the following files are already on the destination directory:
- 2021-07-22_AppName.xml
- 2021-07-22_AppName.1.xml
- 2021-07-22_AppName.2.xml
- 2021-07-22_AppName.3.xml
If I start the application, new log entries will be correctly appended to the main file 2021-07-22_AppName.xml. However, once the size in maximumFileSize is reached, data will be written to 2021-07-22_AppName.1.xml, thus overwriting existing data contained therein.
My expectation would be that the framework recognizes this initial state and 1) appends to the main file, and 2) chooses a filename that continues the rollover sequence (4 in this case).
What have I tried?
Based on this answer, I tried the following
<file type="log4net.Util.PatternString" value="D:\\Logs\\.xml" />
<datePattern value="yyyy-MM-dd'_AppName'" />
Also tried a conversionPattern like
<file type="log4net.Util.PatternString">
<conversionPattern value="D:\Logs\%date{yyyy-MM-dd}_AppName.xml" />
</file>
but it creates files with the date both at the beginning and the end (i.e. 2021-07-22_AppName2021-07-22.xml
I've already looked at this question (I don't have multiple processes/instances logging to the file).
Questions
- Is what I'm trying to do even supported/possible? If so, what am I missing?
- Is there a way to prepend the date to
file.valueor is it always added at the end of the filename right before the extension?