How to enable filters for listener in out-of-process

Topics: Semantic Logging Application Block
Apr 2, 2014 at 5:05 AM
sorry if i'm re-posting the question here again

As per my this post https://entlib.codeplex.com/discussions/540460 and the answer to the 1st question is
"ETW will check to see if any sessions are open and also if the there are any listeners which are enabled for the event metadata (including EventLevel and Keywords). So you shouldn't have to do anything for this to work. You could use the IsEnabled(EventLevel, Keywords) method to check if the event is enabled to improve performance"

But for out-of-process since we are not registering any listener then how do i configure listener? For example below how do i log only Errors, but not information logs into ETW
[EventSource(Name = "SLAB")]
    public class MyEventSource : EventSource
    {
        public class Keywords
        {
            public const EventKeywords Page = (EventKeywords)1;
            public const EventKeywords DataBase = (EventKeywords)2;
            public const EventKeywords Diagnostic = (EventKeywords)4;
            public const EventKeywords Perf = (EventKeywords)8;
        }

        public class Tasks
        {
            public const EventTask Page = (EventTask)1;
            public const EventTask DBQuery = (EventTask)2;
        }

        private static MyEventSource _log = new MyEventSource();
        private MyEventSource() { }
        public static MyEventSource Log { get { return _log; } }

        [Event(1, Message = "Application Failure: {0}",
        Level = EventLevel.Error, Keywords = Keywords.Diagnostic)]
        internal void Failure(string message)
        {
            if (this.IsEnabled(EventLevel.Error, Keywords.Diagnostic))
            {
                this.WriteEvent(1, message);
            }
        }

        [Event(2, Message = "Application Information: {0}",
        Level = EventLevel.Informational, Keywords = Keywords.Page)]
        internal void Info(string message)
        {
            if (this.IsEnabled(EventLevel.Informational, Keywords.Page))
            {
                this.WriteEvent(2, message);
            }
        }

        [NonEvent]
        internal void Failure(Exception ex)
        {
            if (this.IsEnabled(EventLevel.Error, Keywords.Diagnostic))
            {
                Failure(ex.ToString());
            }
        }
    }
Apr 3, 2014 at 5:02 AM
Actually, in the out of process scenario an ETW Session is created where the application does know if there is a session and whether it is enabled or not. With SLAB this is configured using the configuration file:
    <flatFileSink fileName="file.log" name="flat file sink">
      <sources>
        <eventSource name="MyEventSource" level="Informational" matchAnyKeyword="2" />
      </sources>
    </flatFileSink>

To my knowledge, there is no way in ETW to log only informational messages but not error messages. The design of ETW (similar to many logging systems) is if the level is set to Informational then all messages with a level of Informational and lower (or higher depending on how you think about it) are logged. See ETW in C#: Controlling which events get logged in an System.Diagnostics.Tracing.EventSource.

If you really only want to "Informational" messages you could create Keywords and then only enable the keywords you want (in combination).

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to