EventSource activity id and TPL

廉价感情. 提交于 2019-12-10 11:26:44

问题


According to documentation http://msdn.microsoft.com/en-us/library/dn775009%28v=pandp.20%29.aspx current activity id should be handled by TPL. But when I get results, log events from different tasks belong to different activities. To read messages I use out of process SemanticLogging-svc.2.0.1406.1 Workflow is follow:
1. I set activity id, which shall be used. EventSource.SetCurrentThreadActivityId.
2. Then I have some code in same thread, but also can be a lot of code in different threads. Example (log messages from below tasks are logged as different activity ids):

Events.Current.TestMethod3();
Task.WaitAll(Task.Factory.StartNew(() =>
{
    for (int i = 0; i < 10; i++)
    {
        Events.Current.TestMethod1_Sleep(50);
        System.Threading.Thread.Sleep(50);
        Events.Current.TestMethod2_Continue();
    }
}),
Task.Factory.StartNew(() =>
{
    for (int i = 0; i < 10; i++)
    {
        Events.Current.TestMethod1_Sleep(60);
        System.Threading.Thread.Sleep(60);
        Events.Current.TestMethod2_Continue();
    }
}));
Events.Current.TestMethod3();

Any ideas how to solve that? Maybe I shall do special things to solve that?


回答1:


In order to get this to work, you need to enable the TPL Event source as described here.

If you use out of process listeners, then there is bug whereby it is not possible to enable the TPL by name - you must use the TPL EventSource GUID instead.



来源:https://stackoverflow.com/questions/27616738/eventsource-activity-id-and-tpl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!