David Perlman created LOG4NET-363:
-------------------------------------
Summary: System.ObjectDisposedException thrown in
log4net.Layout.XmlLayoutSchemaLog4j.FormatXml ln 47
Key: LOG4NET-363
URL: https://issues.apache.org/jira/browse/LOG4NET-363
Project: Log4net
Issue Type: Bug
Components: Appenders
Affects Versions: 1.2.11
Environment: IIS 7.0
Reporter: David Perlman
Priority: Minor
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 { }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira