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

LogicalThreadContext is not per Thread

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Information Provided
    • Affects Version/s: 2.0.8
    • Fix Version/s: 2.0.8, 2.1.0
    • Component/s: Other
    • Labels:
      None
    • Environment:
      Windows 10, Visual Studio 17, .NET Framework 4.5.2

      Description

      LogicalThreadContext values are spread to many threads when they shouldn't.

      This is an example:

      console.cs
                  LogicalThreadContext.Properties["x-corralation-Id"] = "original-value";
      
                  var list = new List<int> {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
                  Parallel.ForEach(list, (i) =>
                  {
                      if (i == 3)
                          LogicalThreadContext.Properties["x-corralation-Id"] = "modified-value";
      
                      logger.Info($"thread {i}.");
                  });
      

      this is the result

      badresult.txt
      {"timestamp":"2017-04-05T12:31:41.117Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 1.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.132Z", "level":"INFO", "x-corralation-Id" : "modified-value", "logger":"logger", "message":"thread 3.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.273Z", "level":"INFO", "x-corralation-Id" : "modified-value", "logger":"logger", "message":"thread 4.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.273Z", "level":"INFO", "x-corralation-Id" : "modified-value", "logger":"logger", "message":"thread 6.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.274Z", "level":"INFO", "x-corralation-Id" : "modified-value", "logger":"logger", "message":"thread 8.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.274Z", "level":"INFO", "x-corralation-Id" : "modified-value", "logger":"logger", "message":"thread 0.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.219Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 7.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.179Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 5.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.273Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 2.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.234Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 9.", "data":(null)} 
      

      This is what I was expecting:

      goodresult.txt
      {"timestamp":"2017-04-05T12:31:41.117Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 1.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.132Z", "level":"INFO", "x-corralation-Id" : "modified-value", "logger":"logger", "message":"thread 3.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.273Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 4.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.273Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 6.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.274Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 8.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.274Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 0.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.219Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 7.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.179Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 5.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.273Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 2.", "data":(null)} 
      {"timestamp":"2017-04-05T12:31:41.234Z", "level":"INFO", "x-corralation-Id" : "original-value", "logger":"logger", "message":"thread 9.", "data":(null)} 
      

        Attachments

          Activity

            People

            • Assignee:
              nachbarslumpi Dominik Psenner
              Reporter:
              husainalshehhi Husain Alshehhi
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: