在此模式下不允许 Log4net 递归读取锁定获取
Log4net Recursive read lock acquisitions not allowed in this mode
我有一个自定义的 log4net appender,如下所示:
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
}
}
}
时不时地,我会在输出中看到这个异常:
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)
appender 似乎工作正常,我的应用程序没有显示任何错误,但这些消息太烦人了。我喜欢干净的 运行 软件,这不是干净的 =(
我的 appender 实现可以吗?我可以包含一些配置来避免此错误吗?我能从 gooogs 中找到的最接近的答案来自这个错误报告 log4net bug。我没有调用 GetAppenders,因此它不适用于我的用例。如有任何帮助,我们将不胜感激。
就我而言,这发生在我的 Appender
调用正在记录的代码时。因此,出现了递归日志记录。如下图所示:
-> Appender -> MyClassThatLogs -> Appender -> MyClassThatLogs -> etc...
另请参阅此 SO post:
我有一个自定义的 log4net appender,如下所示:
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
}
}
}
时不时地,我会在输出中看到这个异常:
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)
appender 似乎工作正常,我的应用程序没有显示任何错误,但这些消息太烦人了。我喜欢干净的 运行 软件,这不是干净的 =(
我的 appender 实现可以吗?我可以包含一些配置来避免此错误吗?我能从 gooogs 中找到的最接近的答案来自这个错误报告 log4net bug。我没有调用 GetAppenders,因此它不适用于我的用例。如有任何帮助,我们将不胜感激。
就我而言,这发生在我的 Appender
调用正在记录的代码时。因此,出现了递归日志记录。如下图所示:
-> Appender -> MyClassThatLogs -> Appender -> MyClassThatLogs -> etc...
另请参阅此 SO post: