3

我有一个演示解决方案,它使用 System.Diagnostics.Tracing.EventSource 类引发事件。我的课程如下:-

[EventSource(Guid = "B6741490-9F53-4620-A45C-49004C1B4444", Name = "DemoEvent")]
sealed public class DemoEventSource : EventSource
{
    [Event(1, Level = EventLevel.LogAlways, Keywords = EventKeywords.None)]
    public void RaiseEvent()
    {
        this.WriteEvent(1, "Found");
    }
}

我按照此处给出的步骤使用 PerfView 工具查看此解决方案生成的事件。我已经*DemoEvent在 PerfView 的附加提供者部分给出了。但是,我无法在 PerfView 的输出中看到这些事件。有人能帮我一下吗?

4

1 回答 1

2

您的方法的参数类型和调用 write 事件的参数类型必须匹配(添加一个整数第一个参数,就像事件 id 一样),以便自动生成的事件源元数据匹配。IE

[Event(1, Level = EventLevel.LogAlways, Keywords = EventKeywords.None)]
public void RaiseEvent(string message)
{
    this.WriteEvent(1, message);
}

避免提供 GUID。.NET 作者的事件源编程指南中建议您只提供名称并让 GUID 从名称中自动生成。

确保您使用的是来自 GitHub 的最新 PerfView 版本,而不是 Microsoft 下载中的过时版本。

于 2018-05-02T19:19:27.550 回答