Is it possible to subclass an EventSource in ETW?

I'd like to be able to declare an EventSource which has a minimum of several methods which by default provide regular logging facilities.

eg

  • Info()
  • Warn()
  • Error()
  • In addition I'd like to be able to within each service, define a specific event source that inherits from the base class providing the above. At the moment the EventRegister.exe app which creates the manifest complains that the event source must be sealed.

    Am I doing this wrong? If so how can I achieve the above? See example code:

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

    I'm using the latest and greatest Microsoft.Diagnostics.Tracing (pre) which I understand has support for Channels unlike the SLAB from Enterprise Library.


    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.

    链接地址: http://www.djcxy.com/p/16136.html

    上一篇: 系统调用:sys之间的区别

    下一篇: 是否有可能在ETW中继承EventSource?