7

我希望能够声明一个 EventSource,它至少有几个默认提供常规日志记录工具的方法。

例如

  • 信息()
  • 警告()
  • 错误()

此外,我希望能够在每个服务中定义一个从提供上述内容的基类继承的特定事件源。目前,创建清单的 EventRegister.exe 应用程序抱怨必须密封事件源。

我做错了吗?如果是这样,我该如何实现上述目标?见示例代码:

    public class ETWBase : EventSource
    {
        [Event(1, Channel = EventChannel.Admin, Message = "Info Message: {0}")]
        public void Info(string message) { this.WriteEvent(1); }

        [Event(2, Channel = EventChannel.Debug, Message = "Debug Message: {0}")]
        public void Trace(string message) { this.WriteEvent(2); }

    }

    [EventSource(Name = "ABC-MyEtwServiceEventSource")]
    public sealed class MyEtwServiceEventSource : ETWBase
    {
        public static MyEtwServiceEventSource Log = new MyEtwServiceEventSource();

        [Event(3, Channel = EventChannel.Debug, Message = "My specific Message: {0}")]
        public void Trace(string message) { this.WriteEvent(3); }       
    }

我正在使用最新最好的 Microsoft.Diagnostics.Tracing(pre),据我了解,它支持 Channels,这与 Enterprise Library 中的 SLAB 不同。

4

1 回答 1

3

ETWBase should be abstract and should not have methods decorated by EventAttribute.

You could find more information in documentation file _EventSourceUsersGuide.docx that is being added to your project if you are referencing Event Source or Event Source Samples nuget packages.

于 2015-04-15T17:54:29.023 回答