Logging woes with log4net and enterprise sites
A fundamental issue that has many effects, is that EPiServer in enterprise mode runs several web sites, potentially in different App Pools, with a single common application root directory – and therefore also a single common configuration file. This causes several issues with the scheduler as well as with Web.Config settings – but today I want to share a small tidbit gleaned about log4net in this context.
The problem is that log4net by default will lock the log file, and thus only allow the first site started to actually log.
Log4net supports handling this in various ways with the RollingFileAppender and FileAppender classes, but the syntax is less than clear.
There’s a property named LockingMode that controls this, but somewhat surprisingly, this is not a setting value – it’s a type reference. This is actually a plug-in point for any custom handling of log file locking. I have not done so, but this may be a very nice place to handle enterprise logging in a nicer way.
Anyway, the proper syntax for Locking mode in the FileAppender and RollingFileAppender elements is:
<lockingModel type=”log4net.Appender.FileAppender+MinimalLock” />
If this is not correctly done, logging will silently fail. Actually… Not quite silently! If you want to ensure that things are going right with your logging – check the logging logging! You enable debug-level log4net internal logging in Web.Config with:
<appSettings>
<add key=”log4net.Internal.Debug” value=”true” />
</appSettings>
Finally, to see the output either start a Visual Studio debugger and observe the ‘output’ window, or get hold of DbgView from the Sysinternals Suite.
21 January 2009