Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-363

System.ObjectDisposedException thrown in log4net.Layout.XmlLayoutSchemaLog4j.FormatXml ln 47

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Duplicate
    • 1.2.11
    • 1.2.12
    • Appenders
    • IIS 7.0

    Description

      On line 47 in XmlLayoutSchemaLog4j there is a reference to the LoggingEvent.Identity property. If this call is made after the web request is finished (from a different thread) the logger throws (below the exception is my sad workaround):

      log4net:ERROR [UdpAppender] ErrorCode: WriteFailure. Unable to send logging event to remote host ------- on port ----.
      System.ObjectDisposedException: Safe handle has been closed
      at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
      at Microsoft.Win32.Win32Native.GetTokenInformation(SafeTokenHandle TokenHandle, UInt32 TokenInformationClass, SafeLocalAllocHandle TokenInformation, UInt32 TokenInformationLength, UInt32& ReturnLength)
      at System.Security.Principal.WindowsIdentity.GetTokenInformation(SafeTokenHandle tokenHandle, TokenInformationClass tokenInformationClass)
      at System.Security.Principal.WindowsIdentity.get_User()
      at System.Security.Principal.WindowsIdentity.GetName()
      at System.Security.Principal.WindowsIdentity.get_Name()
      at log4net.Core.LoggingEvent.get_Identity()
      at log4net.Layout.XmlLayoutSchemaLog4j.FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
      at log4net.Layout.XmlLayoutBase.Format(TextWriter writer, LoggingEvent loggingEvent)
      at log4net.Appender.AppenderSkeleton.RenderLoggingEvent(LoggingEvent loggingEvent)
      at log4net.Appender.UdpAppender.Append(LoggingEvent loggingEvent)

      Workaround -----

      // translate identity name
      // When logging on a thread that continues (asynchronously) after the web request is finished this will throw the logging
      try
      {
      if (loggingEvent.Identity != null &&
      loggingEvent.Identity.Length > 0 &&
      loggingEvent.LookupProperty(LoggingEvent.IdentityProperty) == null)

      { loggingEvent.GetProperties()[LoggingEvent.IdentityProperty] = loggingEvent.Identity ?? "identity lost"; }

      }
      catch { }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ondesertverge David Perlman
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: