[ 
https://issues.apache.org/jira/browse/LOG4NET-562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15960776#comment-15960776
 ] 

Husain Alshehhi edited comment on LOG4NET-562 at 4/7/17 1:30 PM:
-----------------------------------------------------------------

[~ahouben] You are right. I posted the problem here: 
https://github.com/dotnet/corefx/issues/17968#issuecomment-292198196. The 
summary is that parallel actually reuses the thread without clearing the 
threadcontext.

[~nachbarslumpi] Your intuition is spot on. The thread is being reused.
{code}
{"timestamp":"2017-04-07T13:29:24.526Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 1 with threadid 1.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.535Z", "level":"INFO", "x-corralation-Id" : 
"modified-value", "logger":"logger", "message":"thread 3 with threadid 3.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.539Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 9 with threadid 4.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.534Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 5 with threadid 5.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.536Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 7 with threadid 6.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.590Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 6 with threadid 5.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.591Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 8 with threadid 6.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.589Z", "level":"INFO", "x-corralation-Id" : 
"modified-value", "logger":"logger", "message":"thread 4 with threadid 3.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.590Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 0 with threadid 4.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.588Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 2 with threadid 1.", 
"data":(null)} 

{code}

This issue can be closed.


was (Author: husainalshehhi):
[~ahouben] You are right. I posted the problem here: 
https://github.com/dotnet/corefx/issues/17968#issuecomment-292198196. The 
summary is that parallel actually reuses the thread without clearing the 
threadcontext.

[~nachbarslumpi] Your intuition is spot on. The thread is being reused.
{code}
{"timestamp":"2017-04-07T13:29:24.526Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 1 with threadid 1.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.535Z", "level":"INFO", "x-corralation-Id" : 
"modified-value", "logger":"logger", "message":"thread 3 with threadid 3.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.539Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 9 with threadid 4.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.534Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 5 with threadid 5.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.536Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 7 with threadid 6.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.590Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 6 with threadid 5.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.591Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 8 with threadid 6.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.589Z", "level":"INFO", "x-corralation-Id" : 
"modified-value", "logger":"logger", "message":"thread 4 with threadid 3.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.590Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 0 with threadid 4.", 
"data":(null)} 
{"timestamp":"2017-04-07T13:29:24.588Z", "level":"INFO", "x-corralation-Id" : 
"original-value", "logger":"logger", "message":"thread 2 with threadid 1.", 
"data":(null)} 

{code}

This issue can be closed.

> LogicalThreadContext is not per Thread
> --------------------------------------
>
>                 Key: LOG4NET-562
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-562
>             Project: Log4net
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 2.0.8
>         Environment: Windows 10, Visual Studio 17, .NET Framework 4.5.2
>            Reporter: Husain Alshehhi
>
> LogicalThreadContext values are spread to many threads when they shouldn't.
> This is an example:
> {code:title=console.cs|borderStyle=solid}
>             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}.");
>             });
> {code}
> this is the result
> {code:title=badresult.txt|borderStyle=solid}
> {"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)} 
> {code}
> This is what I was expecting:
> {code:title=goodresult.txt|borderStyle=solid}
> {"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)} 
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to