EventSource in .NET 4.6 & Event Viewer

有些话、适合烂在心里 提交于 2019-12-06 10:25:37

问题


I'd like to ask a very specific question about writing to the event viewer using the System.Diagnostics.Tracing.EventSource and .NET 4.6 class.

In the past, if you wanted to use the event viewer channels you needed to write/generate an XML manifest and register it with the operating system. Is this still the case?

If so I'm struggling to find out how to get the build to generate the manifest, I belive this is possible with the EventSource nuget package, but I'd like to use the in built class under the System.Diagnostics.Tracing namespace if possible.

Thanks in advance.


回答1:


Take a look at the Microsoft EventRegister Tool package on NuGet:

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).

Install it via Package Management console in VS:

Install-Package Microsoft.Diagnostics.Tracing.EventRegister

This registers your Eventsource classes, so that you can write to 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);
    }
}



来源:https://stackoverflow.com/questions/38054541/eventsource-in-net-4-6-event-viewer

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