My first answer (below) was based on v1.2.10 of log4net and I was gently prodded towards the v1.2.13 version which does contain the preserveLogFileNameExtension
. Some tests confirmed that the property also works as intended, and is not dependent on the staticLogFilename
property.
I think that OP is using a previous version of log4net that doesn't contain the property and thus exhibits the behavior described below (making3 and Sivakumar comment are on the spot IMO)
Thank again for waking me out of the 1.2.10 groove.
Initial answer
First thing first: there is no preserveLogFileNameExtension
property for a RollingFileAppender
(or any appender) in vanilla log4net (I'm looking at version 1.2.10.0). Most log4net components will consume any property configuration you send their way without complaining but it doesn't necessarily translate to a behavior in the component
When rolling on size (or composite), what happens is that the rolling over is hardcoded to suffix the log file with the iteration number. You will always get a "file.log.n" with n matching the next file number (which depends on your maxSizeRollBackups
and countDirection
values). You cannot avoid this with the current RollingFileAppender
(take a look at the RollingFileAppender.RollOverRenameFiles
method)
What to do? You can decide to roll by date. In this case it is possible to use the datePattern
property. The datePattern
is appended to the file name when rolling, so you can use something like
<file value="file.log" />
<datePattern value=".yyyy-MM-dd-hh-mm-ss'.log'" />
which would preserve the extension and create a file like file.log.2014-12-11-11-47-54.log
(see the original .log extension in the file name). But you are losing the size limitation aspect. if you go for Composite you will encounter the same problem; since RollOverSize
always occur after RollOverDate
the number prefix will be present.
You can also decide to roll out (ah ah) your own appender with the naming conventions you want/need. You could even try to inherit from the vanilla RollingFileAppender
and only override necessary method. AdjustFileBeforeAppend
is virtual and is the starting point for all rollovers needs; you could try for example to reverse the calls to RollOverDate
and RollOverSize
to use the Composite mode...
<layout type="log4net.Layout.PatternLayout">
? Outside of changing that to fix an log4net exception, this works for me on version 1.2.13. – Bale