Thank you very much for your answer. 

I'll take a close look at it.

 

Have a nice day.

 

 

Bruno Knittel 

-----Ursprüngliche Nachricht-----
Von: Ron Grabowski [mailto:[EMAIL PROTECTED] 
Gesendet: Mittwoch, 9. Januar 2008 23:32
An: Log4NET User
Betreff: Re: AW: Error handling: how to be sure logs were correctly written ?

 

You could extend the OnlyOnceErrorHandler to add an event so outsiders can know 
when an appender error has occurred:

// untested
public class PublishingOnlyOnceErrorHandler : OnlyOnceErrorHandler
{
    public static event EventHandler<ErrorHandlerEventArgs> ErrorOccurred;

    public new void Error(string message, Exception e, ErrorCode errorCode)
    {
        base.Error(message, e, errorCode);

        if (ErrorOccurred != null)
        {
            ErrorOccurred(this, new ErrorHandlerEventArgs(this));
        }
    }
}

// untested
public class ErrorHandlerEventArgs : EventArgs
{
    private OnlyOnceErrorHandler errorHandler;

    public ErrorHandlerEventArgs(OnlyOnceErrorHandler errorHandler)
    {
        this.errorHandler = errorHandler;
    }

    public OnlyOnceErrorHandler ErrorHandler
    {
        get { return errorHandler; }
    }
}

Then when you configure the repository you can replace the default error 
handler with your own:

// untested
PublishingOnlyOnceErrorHandler.ErrorOccurred += delegate(object instance, 
ErrorHandlerEventArgs e)
{
    DialogResult result = MessageBox.Show("An error has occurred." + 
Environment.NewLine + e.ErrorHandler.ErrorMessage);

    if (result == DialogResult.OK)
    {
        // Reset method is not available in the current release of log4net.net
        e.ErrorHandler.Reset(); 
    }
};

// untested
foreach (IAppender appender in rep.GetAppenders())
{
    AppenderSkeleton appenderSkeleton = 
        (AppenderSkeleton)appender;

    if (appenderSkeleton != null)
    {
         // a better idea might be to wrap the existing error handler instead 
of replacing it
        appenderSkeleton.ErrorHandler = new PublishingOnlyOnceErrorHandler();
    }
}

Another thing to be aware of is that IErrorHandler is focused on appenders. 
Errors can occur other places too. For example an error could occur if an 
invalid format string is sent to one of the DebugFormat methods. In that case 
an error has occurred before the output was sent to the appender. There isn't a 
good way of catching those right now. In the next release you'll be able to 
more easily listen for internal error messages like this (this is fairly new so 
its subject to change):

LogLog.LogReceived += delegate(object instance, LogReceivedEventArgs e)
{
    if (e.LogLog.Source is SystemStringFormat)
    {
        // alert user of invalid DebugFormat arguments
    }
};

----- Original Message ----
From: Knittel Bruno <[EMAIL PROTECTED]>
To: Log4NET User <log4net-user@logging.apache.org>
Sent: Wednesday, January 9, 2008 1:20:10 AM
Subject: AW: Error handling: how to be sure logs were correctly written ?

Hello,

 

            First let me thank your for your answer.

            I read the FAQ and know that log4net is not a reliable system. My 
question was more about the work that is needed to make it reliable.

            I know what it implies to have this "reliability" but we simply do 
not have any other choice. Our products have to be able to log certain entries 
in a reliable way.

 

             So I'll have to modify the Appenders, but my main question was: 
how to get an error status back to the application from the log4net methods. If 
log is not successful our software may need to decide to inform the user and 
wait for him to solve the problem before the application can be further used. I 
know this is not supported by log4net, but I saw an IErrorHandler 
(http://logging.apache.org/log4net/release/sdk/log4net.Core.IErrorHandler.html) 
and wondered if I could not start something with this.

 

            Do you think it is feasible without too much work?

 

            Thank you very much for your help,

 

Bruno Knittel
 

-----Ursprüngliche Nachricht-----
Von: Ron Grabowski [mailto:[EMAIL PROTECTED] 
Gesendet: Dienstag, 8. Januar 2008 18:48
An: Log4NET User
Betreff: Re: Error handling: how to be sure logs were correctly written ?

 

The FAQ states that log4net is not a reliable logging system:

 http://logging.apache.org/log4net/release/faq.html

If you want something that is truly reliable my guess is that you'd have to 
check the target to make sure information was received correctly. Maybe the 
EventLog, syslog, or a message queue guarantee reliability. What happens when 
the EventLog reaches its maximum size? 

In the case of a FileAppender you might be able to turn on flushing after every 
write then check to the length of the file (or open the file and seek to the 
end) to make sure data has been written. CountingQuietTextWriter keeps track of 
the number of bytes written to a file.

Verifying every message is written will definitely slow things down.

----- Original Message ----
From: Knittel Bruno <[EMAIL PROTECTED]>
To: log4net-user@logging.apache.org
Sent: Monday, January 7, 2008 6:11:18 AM
Subject: Error handling: how to be sure logs were correctly written ?

Hello everyone,

 

            We need a logging framework that runs on CF 2.0 (as log4net exists 
for CF 1.0, it runs on CF 2.0) that can assure us that log was successfully 
performed on every Appender.

 

            In fact we want our application to be told by the logging framework 
if log was successful. 

 

Is this possible with the log4net framework?

If yes, what about the TCP/IP network appenders?

 

Thanks in advance for your help,

 

Bruno Knittel 

 

 

 

Reply via email to