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: log4net exception handling
Date Tue, 13 Dec 2005 17:33:21 GMT
You can write a custom error handler and attach it to the file appender.
The log4net.Core.IErrorHandler interface defines the error handler. The
appender has a property ErrorHandler which can be set to a custom error
handler instance. The default error handler writes the error message to
the log4net internal debug system.

The FileAppender will call the ErrorHandler object to log if the file
cannot be opened. You can develop a custom error handler in your app
that notifies the admin via some other means. 

Cheers,
Nicko

> -----Original Message-----
> From: Ramaa Davanagere [mailto:RDAVANAG@mobius.com] 
> Sent: 12 December 2005 16:51
> To: 'Log4NET User'
> Subject: RE: log4net exception handling
> 
>  
> 
> Well, I have a special situation and I'm not sure how to handle it...
> 
>  
> 
> I have lot of components using log4net for tracing, logging, 
> etc and they all use a single file for logging.  If for some 
> reason, if a component hangs, the logfile is locked and there 
> after nothing is logged into the log file.  In this scenario, 
> I need to notify the administrator that logging has stopped 
> because of the File Lock problem so that he can take action. 
> How do I solve this problem?
> 
>  
> 
> Bottom line, I need to notify the administrator if the 
> logging has stopped working.
> 
>  
> 
> -----Original Message-----
> From: Matthew Brown [mailto:octavius@gmail.com]
> Sent: Monday, December 12, 2005 11:21 AM
> To: Log4NET User
> Subject: Re: log4net exception handling
> 
>  
> 
> For most people, it's far more annoying for the application 
> to fail because of a logging error than because of a true 
> application error:
> 
> http://logging.apache.org/log4net/release/faq.html#reliability
> 
> Is log4net a reliable logging system?
> 
> No. log4net is not reliable. It is a best-effort and 
> fail-stop logging system.
> 
> By fail-stop, we mean that log4net will not throw unexpected 
> exceptions at run-time potentially causing your application 
> to crash. If for any reason, log4net throws an uncaught 
> exception (except for ArgumentException and 
> ArgumentNullException which may be thrown), please send an 
> email to the log4net-user@logging.apache.org mailing list. 
> Uncaught exceptions are handled as serious bugs requiring 
> immediate attention.
> 
> Moreover, log4net will not revert to System.Console.Out or 
> System.Console.Error when its designated output stream is not 
> opened, is not writable or becomes full. This avoids 
> corrupting an otherwise working program by flooding the 
> user's terminal because logging fails. However, log4net will 
> output a single message to System.Console.Error and 
> System.Diagnostics.Trace indicating that logging can not be performed.
> 
> 
> 
> On 12/12/05, Ramaa Davanagere <RDAVANAG@mobius.com> wrote: 
> >  
> >  
> > 
> > Following is the method that logs messages to the log file. 
>  Logger is 
> > initiliazed correctly before calling this method.  If there is any 
> > error in
> > LogMessage() method, errors are logged to application event 
> log. What 
> > I don't understand is, if the log file that is used for logging 
> > messages is currently locked, an exception is not raised in 
> the code 
> > below. The code continues to work as if it logged the 
> messages to the 
> > log file. Why doesn't the code jump to exception handling, 
> if log4net is not able to log message.
> > How can I force it to jump to exception handling, if there is any 
> > problem with log4net?
> > 
> >   
> > 
> > public void LogMessage(string sMessage, int nLoggingLevel)
> > 
> > {
> > 
> >       try
> > 
> >       {
> > 
> >             switch((eLogging_Level) nLoggingLevel)
> > 
> >             {
> > 
> >                   case eLogging_Level.eInfo: 
> > 
> >                         logger.Info(StripSecureData(sMessage));
> > 
> >                         break;
> > 
> >                   case eLogging_Level.eError: 
> > 
> >                         logger.Error(sMessage);
> > 
> >                         break;
> > 
> >                   case eLogging_Level.eDebug: 
> > 
> >                         logger.Debug(StripSecureData(sMessage));
> > 
> >                         break;
> > 
> >                   case eLogging_Level.eWarning: 
> > 
> >                         logger.Warn(sMessage);
> > 
> >                         break;
> > 
> >                   case eLogging_Level.eFatal: 
> > 
> >                         logger.Fatal(sMessage);
> > 
> >                         break;
> > 
> >                   default: 
> > 
> >                         //do stuff here;
> > 
> >                         break;
> > 
> >             }
> > 
> >       }
> > 
> >       catch(Exception ex)
> > 
> >       {
> > 
> >             EventLog.WriteEntry("ErrorHandler","Error in " +
> > System.Reflection.MethodBase.GetCurrentMethod() + ": " + 
> ex.Message, 
> > EventLogEntryType.Error);
> > 
> >       }
> > 
> > }
> 
> 

Mime
View raw message