.NET 4.6 和事件查看器中的事件源

EventSource in .NET 4.6 & Event Viewer

我想问一个关于使用 System.Diagnostics.Tracing.EventSource 和 .NET 4.6 class.

写入事件查看器的非常具体的问题

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

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

提前致谢。

看看 NuGet 上的 Microsoft EventRegister Tool 包:

This package includes eventRegister.exe, which enables validation and registration of user defined EventSource classes. It supports both BCL event sources (classes derived from System.Diagnostics.Tracing.EventSource) and NuGet event sources (classes derived from Microsoft.Diagnostics.Tracing.EventSource).

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

Install-Package Microsoft.Diagnostics.Tracing.EventRegister

这会注册您的事件源 类,以便您可以写入事件日志:

[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);
    }
}