I still dont really get it how to change log4net if I would like to have every x hour a log. I have this:
<log4net>
<root>
<level value="DEBUG"/>
<appender-ref ref="LogFileAppender"/>
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="C:\log.txt"/>
<param name="AppendToFile" value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="100MB"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n"/>
</layout>
</appender>
</log4net>
I have one log and Im adding the logs always in this one log.txt - now I would like to have lets say for every day a new log file (24hours) or maybe for every 12hours a new log. What do I have to change in my config? Any suggestions to my config? Thank you
RE: http://logging.apache.org/log4net/release/config-examples.html
This example shows how to configure the RollingFileAppender to roll log files on a date period. This example will roll the log file every minute! To change the rolling period adjust the DatePattern value. For example, a date pattern of "yyyyMMdd" will roll every day. See
System.Globalization.DateTimeFormatInfo
for a list of available patterns.In your particular case, the above example with
<datePattern value="yyyyMMdd-HH" />
would only allow you to log every hour.However, if you wanted to log every
X
hour, you could create a custom appender derived fromRollingFileAppender
and override theAdjustFileBeforeAppend
method that would check the current time against your next scheduled log interval date. See Have a Log4Net RollingFileAppender set to roll weekly for example.Replace your rolling style as follows:
You'll probably also want to remove the file size limitation.