Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-437

LogicalThreadContext data does not flow properly using Async and Await

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.2.9, 1.2.10, 1.2.11, 1.2.12, 1.2.13
    • 1.3.0
    • Core
    • None
    • Windows 7, .NET 4.5

    Description

      LogicalThreadContext doesn't work properly when using Async and Await. The current NDC call stack gets corrupted because the logical data context is not immutable. (See: http://blog.stephencleary.com/2013/04/implicit-async-context-asynclocal.html for the gory details). I've attached a Program.cs that demonstrates the issue. You will see with an unpatched log4net the thread context is corrupted compared to the proper implementation in MyStack and the console logger. An entry like:

      LOG4NET Main 1 A 2 A: </MoreWork>
      LOG4NET Main 1 A 2 A: </MoreWork>

      is invalid and should not be possible in a properly working thread context.

      I've attached a VERY naive patch that corrects the issue.

      Attachments

        1. LogicalThreadContext.diff
          2 kB
          Mike Barry
        2. Program.cs
          3 kB
          Mike Barry
        3. ThreadContextStacks.diff
          0.4 kB
          Mike Barry

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jabbera Mike Barry
              Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: