'Log4net : Rolling File Operation : Failing with Source does not exist
We are using log4net in our multi-threaded WCF windows service since last 3 years or so. We have recently encountered that our service became unresponsive/went into hanging state couple of time. While analyzing crash dump of the service of that time, we have encountered that one of our thread has failed during rolling file operation. The stack trace of failed thread as follows :
log4net.Util.LogLog.EmitErrorLine(System.String)
log4net.Util.LogLog.Warn(System.Type, System.String)
log4net.Appender.RollingFileAppender.RollFile(System.String, System.String)
log4net.Appender.RollingFileAppender.RollOverTime(Boolean)
log4net.Appender.RollingFileAppender.AdjustFileBeforeAppend()
log4net.Appender.RollingFileAppender.Append(log4net.Core.LoggingEvent)
log4net.Appender.AppenderSkeleton.DoAppend(log4net.Core.LoggingEvent)
....
....
While going through error thrown by above stack trace, we have encountered following error message :
log4net:WARN Cannot RollFile [....] -> [....]. Source does not exist
All other threads are waiting at following log4net method :
log4net.Appender.AppenderSkeleton.DoAppend(log4net.Core.LoggingEvent)
log4net.Util.AppenderAttachedImpl.AppendLoopOnAppenders(log4net.Core.LoggingEvent)
....
....
Rolling File Date Pattern is as following :
<datePattern value=".yyyyMMdd-HH".log"">
We are not able to understand what is exactly wrong over here which causes service to become unresponsive. Does rolling file operation cause the thread, which is using it, to go into unresponsive state if some error occurs ? We have gone through other posts which are telling to use different datepattern on log4net forum but changing datepattern is not solving problem for everybody. We would like to know what is the full proof way to solve this issue.
Thanks.
Solution 1:[1]
I found that I was getting this error after I had done some testing. We set our log files to roll on a daily basis. For testing purposes, I made my system write a bunch of files for "today". Then I set the date on my computer forward a day and re-ran things. As expected, the log files were renamed to the previous day and new log files were written for the new day.
Successful test!
I reset the date back to the proper date and began again. That's when I got this error. As near as I can tell, it was trying to roll the previous day files incorrectly.
To resolve the problem I simply cleared out all the log files and let it start from scratch.
Solution 2:[2]
I had this problem after playing around with different options of my file appender.
Solution: Deleted all created logfiles (which had different file formats including time stamps).
Thanks @ markdotnet, who gaves a good hint.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | markdotnet |
Solution 2 | Beauty |