This project has moved. For the latest updates, please go here.

Log file locked up during IIS application pool recycle

Sep 10, 2012 at 10:17 AM

I have a problem when using essential diagnostics' RollingFileTraceListener in an ASP.NET MVC 3 app. During application pool recycling, IIS 6 creates a new process while keeping the old process alive until the old process finished servicing all pending requests. I found a documentation of it at this link:

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/24e3c22e-79a9-4f07-a407-dbd0e7f35432.mspx?mfr=true

So, during app pool recycling there are two processes running and if both processes try to write to the same log file, one process will fail, usually the new process, until the old process is terminated.

Is it possible to modify RollingFileTraceListener to use mutex or release the write lock when not writing to the log file so both processes can write to the same log file?

Or is there a better way?

Coordinator
Nov 11, 2012 at 3:53 AM

I suggest adding a feature request in the issue tracker. 

There is already a feature request for multiple listeners in the one process sharing a log file; some kind of in-memory locking should be sufficient for this (to ensure complete messages are written at a time). 

For separate processes, however, it would need some more co-ordination (possibly locking for write, then releasing the handle for the other process to access), which may be too resource intensive for a tracing framework.

There was also another feature request around simply appending a sequential number to create a new file, which may at least be a work around.