I used this config but a date is always added to the current file ('log.20130805.0.log').
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Logs/logFile.log" />
<appendToFile value="true" />
<preserveLogFileNameExtension value="true" />
<rollingStyle value="Composite" />
<datePattern value=".yyyyMMdd" />
<maximumFileSize value="10MB" />
<countDirection value="1"/>
<maxSizeRollBackups value="-1" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
The result of that config is :
log.20130805.0.log
log.20130805.1.log
log.20130805.2.log
log.20130805.3.log
What I get with staticLogFileName = true is :
log.log
log.1.log
log.2.log
log.3.log
What I want is :
log.log
log.20130805.1.log
log.20130805.2.log
log.20130805.3.log
I know I'm late to the party, but I believe I have figured out how to use a composite RollingFileAppender properly. I'm posting it here for posterity, in case anyone stumbles upon this in a search:
<appender name="rollingfileappender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Logs\logfile.log" />
<datePattern value=".yyyyMMdd" />
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100Kb" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.DynamicPatternLayout">
<conversionPattern value="%[level] - %date - %message" />
</layout>
</appender>
The key here is:
<preserveLogFileNameExtension value="true" />
and
<staticLogFileName value="true" />
When your current log files are being appended, you'll see:
logfile.log
logfile.1.log
logfile.2.log
etc...
Once the new day hits, those should be renamed to:
logfile.20200623.log
logfile.20200623.1.log
logfile.20200623.2.log
etc...
and you'll have a new logfile.log, still catching your current logs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With