Log4net
  1. Log4net
  2. LOG4NET-331

AdoNetAppender errors when writing Asp.net item when Request object is null

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.11
    • Fix Version/s: 1.2.12
    • Component/s: Appenders
    • Labels:
      None
    • Environment:
      Windows Server 2008 R2

      Description

      When using AdoNetAppender, with a conversion pattern of '%aspnet-request

      {REMOTE_ADDR}

      ', and I attempt to write a log entry during the Application_Start event, it throws an error (internally) and stops working. The error refers to "...Request is not available in this context.." which makes sense because its only in the Application_Start event. However the appender should accommodate this situation and log null, not throw an error. The RollingFileAppender, for instance, handles this gracefully.

        Activity

        Hide
        Stefan Bodewig added a comment -

        fixed with svn revision 1345626

        Show
        Stefan Bodewig added a comment - fixed with svn revision 1345626
        Hide
        Ron Grabowski added a comment -

        At first glance it looks like it pattern does account for Request being null:

        // AspNetRequestPatternConverter
        protected override void Convert(TextWriter writer, LoggingEvent loggingEvent, HttpContext httpContext)
        {
        if (httpContext.Request != null)
        {
        if (Option != null)

        { WriteObject(writer, loggingEvent.Repository, httpContext.Request.Params[Option]); }

        else

        { WriteObject(writer, loggingEvent.Repository, httpContext.Request.Params); }

        }
        else

        { writer.Write(SystemInfo.NotAvailableText); }

        }

        Show
        Ron Grabowski added a comment - At first glance it looks like it pattern does account for Request being null: // AspNetRequestPatternConverter protected override void Convert(TextWriter writer, LoggingEvent loggingEvent, HttpContext httpContext) { if (httpContext.Request != null) { if (Option != null) { WriteObject(writer, loggingEvent.Repository, httpContext.Request.Params[Option]); } else { WriteObject(writer, loggingEvent.Repository, httpContext.Request.Params); } } else { writer.Write(SystemInfo.NotAvailableText); } }

          People

          • Assignee:
            Unassigned
            Reporter:
            Andy Smith
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development