EventSource 活动 ID 和 TPL [英] EventSource activity id and TPL

查看:33
本文介绍了EventSource 活动 ID 和 TPL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档http://msdn.microsoft.com/en-us/library/dn775009%28v=pandp.20%29.aspx 当前活动 ID 应由 TPL 处理.但是当我得到结果时,来自不同任务的日志事件属于不同的活动.要读取我使用的进程外 SemanticLogging-svc.2.0.1406.1 的消息工作流程如下:
1.我设置了活动ID,应该使用.EventSource.SetCurrentThreadActivityId.
2.然后我在同一个线程中有一些代码,但也可以在不同的线程中有很多代码.示例(来自以下任务的日志消息被记录为不同的活动 ID):

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?

推荐答案

为了使其工作,您需要启用 TPL 事件源,如此处.

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

如果您使用进程外侦听器,则存在错误,无法按名称启用 TPL - 您必须改用 TPL EventSource GUID.

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.

这篇关于EventSource 活动 ID 和 TPL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆