You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Mike Blake-Knox <mi...@knology.net> on 2004/09/16 20:29:22 UTC

RollingFileAppender Renaming Robustness

I've been using Chainsaw to tail RollingFileAppender log files.  I've found
that the RollingFileAppender is quite sensitive if Chainsaw happens to have
the file open (for read) when RollingFileAppender tries to rename it.

I've put a single delay/retry into RollFile.  Here is a replacement for the
RollFile catch block:

				catch(Exception ex)
				{
					ErrorHandler.Error("Exception while
rolling file [" + fromFile + "] -> [" + toFile + "]", ex,
ErrorCodes.GenericFailure);

					// in case the exception was caused
by trying to rename the file at the moment Chainsaw happened to be reading
it
					// sleep for a second then try again
					Thread.Sleep(1000);
					try 
					{
						file.MoveTo(toFile);
						//
LogLog.Debug("RollingFileAppender: Retry succeeded");
	
ErrorHandler.Error("RollingFileAppender: Retry succeeded");
					}
					catch (Exception ex2)
					{
						ErrorHandler.Error("Retry
failed", ex2, ErrorCodes.GenericFailure);
					}

				}

It uses System.Threading to delay one second.

I hope a single one second delay is tolerable.  It seems to make a great
improvement in the reliability of RollFile operation.

Mike Blake-Knox
email: MBlake-Knox@tsystsol.com
TSYS Office: (706) 644-3643
cellphone: (706) 570-4641