log4net not logging properly when rolling to a new date
Log4Net worked fine for a few months and then started giving problems when rolling out a new file for the next day.
Problem: Whenever I check in the daytime or until 23:59 everything is logged but as soon as it rolls over, the rolled file will have the开发者_如何转开发 data of 00:00 - 06:00 hrs of the next day. All the logs of the previous day are lost.
So for the rolledfile Service.log20100702 will contain the data 00:00 - 06:00 hrs for 03/07/2010 date and nothing else.
The problem is mainly on the Production boxes, it's working fine on my local box.
My rolling file appender looks like
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\TTLLogs\Refunds\Ttl.Refunds.Web.UI.log"/>
<appendToFile value="true" />
<datePattern value="yyyyMMdd" />
<rollingStyle value="Date" />
<maximumFileSize value="10MB" />
<maxSizeRollBackups value="100" />
<layout type="log4net.Layout.PatternLayout">
<header value="[Header]
"/>
<footer value="[Footer]
"/>
<conversionPattern value="%date %-5level %logger ${COMPUTERNAME} %property{UserHostAddress} [%property{SessionID}] - %message%newline"/>
</layout>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
</appender>
I'd try:
- Adding <staticLogFileName value="true" />. This prevents file renaming when the appender rolls the date.
- Change the lockingModel to FileAppender.ExclusiveLock to prevent another process from locking the log file. I.e. maybe a virus scanner of similar is locking the log file.
- Removing maximumFileSize as it isn't applicable when the rollingStyle is Date.
- Removing maxSizeRollBackups as you can manually delete the extra log files until the logging is working as expected again.
精彩评论