logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Brown <octav...@gmail.com>
Subject Re: log4net exception handling
Date Mon, 12 Dec 2005 16:20:51 GMT
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