I've tried all the answers, but there was always something missing and not functioning as expected for me.
Then I experimented a bit with the hints given in each answer and was successful with the following setting:
<appender name="RollingActivityLog" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="C:\temp\LOG4NET_Sample_Activity.log" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<staticLogFileName value="false" />
<preserveLogFileNameExtension value="true" />
<datePattern value="-yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level - %message%newline" />
</layout>
</appender>
The issue with other combinations of parameters was that the latest file didn't have the time pattern, or that the time pattern was appended as .log20171215
which created a new file time (and a new file type!) each day - or both issues appeared.
Now with this setting you are getting files like this one:
LOG4NET_Sample_Activity-20171215.log
which is what I wanted.
To summarize:
Don't put the date pattern in the <file value=...
attribute, just define it in the datePattern
.
Make sure you have the preserveLogFileNameExtension
value attribute set to true
.
Make sure you have the staticLogFileName
value set to false
.
Set the rollingStyle
attribute value to Date
.