.NET 4.6和事件查看器中的EventSource
我想问一个非常具体的问题,即使用System.Diagnostics.Tracing.EventSource和.NET 4.6类写入事件查看器。
过去,如果您想使用事件查看器通道,则需要编写/生成XML清单并将其注册到操作系统。 这仍然是这样吗?
如果是这样,我很难找到如何使构建生成清单,我相信这可以使用EventSource nuget包,但我想使用System.Diagnostics.Tracing命名空间下的in built类,如果可能。
提前致谢。
看一下NuGet上的Microsoft EventRegister Tool包:
该软件包包括eventRegister.exe ,它可以validation和注册用户定义的EventSource类。 它支持BCL事件源(从System.Diagnostics.Tracing.EventSource派生的类)和NuGet事件源(从Microsoft.Diagnostics.Tracing.EventSource派生的类)。
通过VS中的Package Management控制台安装它:
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); } }