Log4net LogicalThreadContext not working as expected

前端 未结 2 1812
说谎
说谎 2020-12-17 19:44

I\'ve been trying to use Log4nets LogicalThreadContext to provide context to each of my log entries. My application uses async/await quite heavily, but from reading various

2条回答
  •  伪装坚强ぢ
    2020-12-17 19:52

    Unfortunately, it looks like log4net still does not work with async logical stacks.

    The log4net NuGet package 2.0.3 is log4net 1.2.13 (the current version as of today). There was a bug reported (LOG4NET-317) because at that time LogicalThreadContext used CallContext instead of LogicalCallContext.

    The current version of LogicalThreadContext does use LogicalThreadContext, but the current version of ThreadContextStacks does not correctly use an immutable stack.

    Interestingly, Andrew Arnott correctly pointed out in the original bug report that they had to use an immutable stack. In 2011.

    Feel free to write up a minimal repro and report it as a log4net bug. The key scenario is using the stack within multiple tasks that are combined using Task.WhenAll.

提交回复
热议问题