Log4net Recursive read locks are not allowed in this mode.

I have a custom log4net application 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 } } } 

From time to time I see this exception in the output file:

 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 application seems to be working fine and my application does not show any errors, but these messages annoy soo. I like clean software to run, and it's not clean = (

Is my appender implementation approved? Is there some kind of configuration that I can enable to avoid this error? The closest answer I can find from gooogs is the log4net error report. I do not call GetAppenders, so it does not apply to my use case. Any help would be assigned.

+5
source share
1 answer

In my case, this happened when my Appender called code that registered. Thus, recursive logging occurred. This is shown below:

 -> Appender -> MyClassThatLogs -> Appender -> MyClassThatLogs -> etc... 

See also this SO publication: logging / handling errors inside a log4net user application

+3
source

All Articles