Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Duplicate
-
1.2.11
-
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)
}
catch { }
Attachments
Issue Links
- duplicates
-
LOG4NET-266 AdoNetAppender does not work on a IIS 7 website using Windows authentication
- Resolved