I have a custom log4net appender that looks like this:
public class MyAppender : AppenderSkeleton
{
protected override void Append(LoggingEvent loggingEvent)
{
try
{
if (loggingEvent.Level == Level.Error || loggingEvent.Level == Level.Fatal)
{
DoWork(RenderLoggingEvent(loggingEvent));
}
}
catch
{
// silently fail
}
}
}
Every now and then, I'll see this exception in the output:
log4net:ERROR Exception while logging
System.Threading.LockRecursionException: Recursive read lock acquisitions not allowed in this mode.
at System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore(TimeoutTracker timeout)
at System.Threading.ReaderWriterLockSlim.TryEnterReadLock(TimeoutTracker timeout)
at System.Threading.ReaderWriterLockSlim.EnterReadLock()
at log4net.Util.ReaderWriterLock.AcquireReaderLock()
at log4net.Repository.Hierarchy.Logger.CallAppenders(LoggingEvent loggingEvent)
at log4net.Repository.Hierarchy.Logger.ForcedLog(Type callerStackBoundaryDeclaringType, Level level, Object message, Exception exception)
at log4net.Repository.Hierarchy.Logger.Log(Type callerStackBoundaryDeclaringType, Level level, Object message, Exception exception)
The appender seems to be working fine and my app does not show any errors but these messages are soo annoying. I like clean running software and this is not clean =(
Is my appender implementation ok? Is there some configuration I can include to avoid this error? The closest answer I can find from the gooogs is from this bug report log4net bug. I'm not calling GetAppenders so it doesn't apply to my use case. Any help would be appriciated.
In my case, this occurred when my Appender
was calling code that was logging. Thus, there was recursive logging occurring. This is visualised below:
-> Appender -> MyClassThatLogs -> Appender -> MyClassThatLogs -> etc...
See also this SO post: logging/error handling inside a custom log4net appender
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With