2

我想问一个关于使用 System.Diagnostics.Tracing.EventSource 和 .NET 4.6 类写入事件查看器的非常具体的问题。

过去,如果您想使用事件查看器通道,您需要编写/生成 XML 清单并将其注册到操作系统。现在还是这样吗?

如果是这样,我正在努力找出如何让构建生成清单,我相信这可以通过 EventSource nuget 包实现,但我想使用 System.Diagnostics.Tracing 命名空间下的内置类 if可能的。

提前致谢。

4

1 回答 1

5

看看 NuGet 上的Microsoft EventRegister Tool包:

这个包包括eventRegister.exe,它可以验证和注册用户定义的 EventSource 类。它支持 BCL 事件源(从 System.Diagnostics.Tracing.EventSource 派生的类)和 NuGet 事件源(从 Microsoft.Diagnostics.Tracing.EventSource 派生的类)。

通过 VS 中的包管理控制台安装它:

Install-Package Microsoft.Diagnostics.Tracing.EventRegister

这会注册您的 Eventsource 类,以便您可以写入 Eventlog:

[EventSource(Name = "Samples-EventSourceDemos-EventLog")]
public sealed class MinimalEventSource : EventSource
{
    public static MinimalEventSource Log = new MinimalEventSource();

    [Event(1, Message="{0} -> {1}", Channel = EventChannel.Admin)]
    public void Load(long baseAddress, string imageName)
    {
        WriteEvent(1, baseAddress, imageName);
    }
}

在此处输入图像描述

于 2016-06-27T14:41:03.520 回答