logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: How to use ErrorHandler
Date Sun, 19 Dec 2004 21:55:46 GMT

Currently log4net does not provide any support for fallback appenders on
error. The IErrorHandler interface does not pass the LoggingEvent object
that was being appended, neither does it provide any semantics for
notifying about recovery from errors. Handling errors is particularly
difficult, errors may occur synchronously or asynchronously. The error
may effect 1 LoggingEvent or multiple LoggingEvents. In some cases the
error will be permanent but in most it will be possible to recover from
the error at some time in the future, but testing if the error still
occurs may be expensive (especially if you can only detect timeouts).

Appenders use their ErrorHandler to report errors. Error handler objects
implement the IErrorHandler interface. The default error handler is the
OnlyOnceErrorHandler. It reports only the first error then ignores
subsequent errors. The reasoning behind this is that if an appender is
reporting an error it will probably just report the same error for each
message logged, this would potentially overload the error reporting
mechanism and may obscure the original cause of the error.

If you want to define your own error handler to report appender errors
in a different way you need to define a class that implements the
IErrorHandler interface. The class can be in another assembly. Then in
the config for the appender you can add an entry for the error handler.

<appender name=".." >
  <errorHandler type="Your.ErrorHandler, YourAssembly" />



> -----Original Message-----
> From: Collier, Mike [mailto:Mike_Collier@stercomm.com] 
> Sent: 17 December 2004 22:26
> To: Log4NET User
> Subject: How to use ErrorHandler
> How would I use the ErrorHandler property for an appender?  
> For example, let's assume I'm using the ADONetAppender and 
> for some reason it fails (i.e. unable to connect to the 
> database server).  I would like to not loose the message.  I 
> was thinking that I could use the ErrorHandler property to 
> define another appender to use in this case.  However, I'm 
> not sure how to do this.  Does anybody have any examples or 
> ideas on how this might be accomplished.
> Thanks!

View raw message