I read an article which told that :
rollingStyle can be either Date, Size or Composite. the default setting Composite, uses a combination of Size and Date settings. Thus if you have the datePattern set to “.yyyy-MM-dd” and maxSizeRollBackups set to 10, themn it will maintain 10 log backups for each day.
If you have the DatePattern set to “.yyyy-MM-dd HH:mm” and maxSizeRollbackups = 10 then it will maintain 10 logfile backups per minute
and it said :
staticLogFileName indicates whether you need to keep writing (log) to the same file all the time. You will need to set it to false when using Date as the rolling style and you have large number of backups.
so i do it in my App.config
:
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="E:\operativity.log" />
<staticLogFileName value="False" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value=".yyyy-MM-dd HH:mm" />
<maxSizeRollBackups value="3" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{dd/MM/yyyy HH:mm:ss.fff} - %level - %message%newline" />
</layout>
</appender>
as you see, i set rollingStyle
to Date
and datePattern
to .yyyy-MM-dd HH:mm
and
set maxSizeRollbackups
to 3
, and i set staticLogFileName
to False
, so it should take three logs in every minute on separate files, but it does not!! what is the problem?
NOTE: this the Link of article
EDIT: I use it in a windowsservice
and it gives me just one log file!
Best Answer
The problem is that you have a : (colon) in the datePattern, its an invalid char for filenames.
you also have to use RollingFileAppender not FileAppender.
Change
To
You will get one file because first file doesnt contain the datetime. And it will fail creating the other files because it contains the : (colon)
This one is tested and it works:
And here is the result: