Log4net
  1. Log4net
  2. LOG4NET-332

I'm looking for the ability to set up a hierarchy of appenders, if a log to an ADONETAppender fails, log4net could then log to one of more "back-up" appenders

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Won't Fix
    • Affects Version/s: 1.2.9
    • Fix Version/s: None
    • Component/s: Appenders
    • Labels:
    • Environment:
      windows 7 , VS2010

      Description

      Basically, I'm looking for the ability to set up a hierarchy of appenders so that if a log to an ADONETAppender fails, log4net could then log to one of more "back-up" appenders, for example, a RollingLogFile or SMTP

        Activity

        Hide
        Ron Grabowski added a comment -

        If you have general usage questions post to the mailing list. This item is closed because its not a bug in log4net.

        Show
        Ron Grabowski added a comment - If you have general usage questions post to the mailing list. This item is closed because its not a bug in log4net.
        Hide
        stalinsubash added a comment -

        Thanks Ron.

        I successfully implemented Failover in ADONetAppender. If ADONet fails then it will rollover to FileAppender \ EventViewerAppender. Here I attached the ADONetAppender class file as well.

        But I FileAppender I’ll fail, I can’t able to get Logging Event in FileAppender class. Here I’ll explain what scenario I tried. I tried to write a log in a text file but the path I mentioned in the configuration file was wrong, so while writing the log it will search the path to open the file in the method (OpenFile) in FileAppender class file, so in the try catch block I implemented below codes as well,

        public override void OpenFile(string filename, bool append,Encoding encoding)
        {
        try

        { m_stream = CreateStream(filename, append, FileShare.Read); }

        catch (Exception ex)
        {
        LoggingEvent[] events = new LoggingEvent[0];
        //events = (LoggingEvent[]);

        string message = "FileAppender failed to find the path";
        // Pass the logging event on to the attached appenders if there are any
        if (iAppenderAttachedImpl != null)

        { iAppenderAttachedImpl.AppendLoopOnAppenders(events); }

        else

        { message += " and there is no appender-ref specified in the configuration for fail-over!"; }

        ErrorHandler.Error(message, ex);
        }
        }

        Could you please advise me on this ASAP?

        Thanks
        Stalin.M

        Show
        stalinsubash added a comment - Thanks Ron. I successfully implemented Failover in ADONetAppender. If ADONet fails then it will rollover to FileAppender \ EventViewerAppender. Here I attached the ADONetAppender class file as well. But I FileAppender I’ll fail, I can’t able to get Logging Event in FileAppender class. Here I’ll explain what scenario I tried. I tried to write a log in a text file but the path I mentioned in the configuration file was wrong, so while writing the log it will search the path to open the file in the method (OpenFile) in FileAppender class file, so in the try catch block I implemented below codes as well, public override void OpenFile(string filename, bool append,Encoding encoding) { try { m_stream = CreateStream(filename, append, FileShare.Read); } catch (Exception ex) { LoggingEvent[] events = new LoggingEvent [0] ; //events = (LoggingEvent[]); string message = "FileAppender failed to find the path"; // Pass the logging event on to the attached appenders if there are any if (iAppenderAttachedImpl != null) { iAppenderAttachedImpl.AppendLoopOnAppenders(events); } else { message += " and there is no appender-ref specified in the configuration for fail-over!"; } ErrorHandler.Error(message, ex); } } Could you please advise me on this ASAP? Thanks Stalin.M
        Ron Grabowski made changes -
        Status Reopened [ 4 ] Closed [ 6 ]
        Resolution Won't Fix [ 2 ]
        Hide
        Ron Grabowski added a comment -

        This isn't a bug in log4net. You need to write your own appender by extending a class like ForwardingAppender:

        <appender name="SimpleRolloverForwardingAppender" type="MyCompany.SimpleRolloverForwardingAppender, MyCompany" >
        <appender-ref ref="AdoNetAppender" />
        <appender-ref ref="SmtpAppender" />
        </appender>

        You don't need to make any changes to log4net.dll to accomplish what you want.

        Show
        Ron Grabowski added a comment - This isn't a bug in log4net. You need to write your own appender by extending a class like ForwardingAppender: <appender name="SimpleRolloverForwardingAppender" type="MyCompany.SimpleRolloverForwardingAppender, MyCompany" > <appender-ref ref="AdoNetAppender" /> <appender-ref ref="SmtpAppender" /> </appender> You don't need to make any changes to log4net.dll to accomplish what you want.
        stalinsubash made changes -
        Resolution Duplicate [ 3 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Hide
        stalinsubash added a comment -

        I need to do some work around in log4net.dll. Please advise me on this ASAP.

        Show
        stalinsubash added a comment - I need to do some work around in log4net.dll. Please advise me on this ASAP.
        Hide
        stalinsubash added a comment -

        Thanks Ron

        You mean i need to do some work arround in log4net dll for this ? . Please advise me on this how to do.

        Show
        stalinsubash added a comment - Thanks Ron You mean i need to do some work arround in log4net dll for this ? . Please advise me on this how to do.
        Hide
        Ron Grabowski added a comment -

        If the AdoNetAppender fails and you switch over to a RollingFileAppender...when do you switch back to the original appender? If/when you switch back to the original appender do you try to re-send captured events? If you want to know if an appender failed you could write a IErrorHandler that sends an email. You could also write a ForwardingAppender that keeps track of a single active appender and rolls to the next one if the first one fails.

        Show
        Ron Grabowski added a comment - If the AdoNetAppender fails and you switch over to a RollingFileAppender...when do you switch back to the original appender? If/when you switch back to the original appender do you try to re-send captured events? If you want to know if an appender failed you could write a IErrorHandler that sends an email. You could also write a ForwardingAppender that keeps track of a single active appender and rolls to the next one if the first one fails.
        Ron Grabowski made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Duplicate [ 3 ]
        Hide
        Ron Grabowski added a comment -
        Show
        Ron Grabowski added a comment - See LOG4NET-1
        stalinsubash created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            stalinsubash
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 24h
              24h
              Remaining:
              Remaining Estimate - 24h
              24h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development