We have been chasing some strange logging bugs for a while in my current project. We are using log4net to do our logging and it works fine ... until a couple of weeks ago. Some logging didn't occur, in another case we didn't get new files...
The fix is, very simple, but quite surprising and I thought I'll share something on what we did to fix it.
We are using a RollingFileAppender and common strategy for how to handle the log files; we're creating a new file for each new date. In order to achieve this we have set the following configuration:
1: <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
2: <file value="{a path here}" />
3: <appendToFile value="true" />
4: <rollingStyle value="Date" />
5: <datePattern value="yyyyMMdd" />
6: <layout type="log4net.Layout.PatternLayout">
7: <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
8: </layout>
9: <filter type="log4net.Filter.LevelRangeFilter">
10: <levelMin value="INFO" />
11: </filter>
12: </appender>
OK – nothing strange here really. And actually it worked fine for a long time. But all of a sudden we have ran into the problems I described above.
The solution is simply to add the “staticLogFileName” element to the configuration above, setting the value to false;
1: <staticLogFileName value="false" />
And with that it started to work again. I found some questions around this on StackOverflow that was related but not exactly this.
So if you name your RollingFiles logs with log4net with Dates – be sure to include the staticLogFileName = false setting.
2 comments:
I have (successfully) used "MinimalLock" for multithreaded applications logging to the same logfile:
Like this:
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
Hey - didn't know you could do that.
Thanks Johan
Post a Comment