This project is read-only.

Keyword filtering

Topics: Using
Aug 15, 2014 at 9:42 AM
I have implemented a listener which I was expecting to write events for a keyword but it also writes any event that doesn't have a keyword defined. How would I exclude events without keywords?

The listener code
ObservableEventListener developerListener = new ObservableEventListener();
            developerListener.LogToRollingFlatFile(@"C:\debug.log", 10000, "(%d+)%-(%d+)%-(%d+)", RollFileExistsBehavior.Increment, RollInterval.Midnight, null, 12, false);
            developerListener.EnableEvents(ClientEventSource.Log, EventLevel.LogAlways, ClientEventSource.Keywords.Developer);
Event source
public class ClientEventSource : EventSource
    {
        public class Keywords
        {
            public const EventKeywords All = (EventKeywords)1;
            public const EventKeywords DataBase = (EventKeywords)2;
            public const EventKeywords Diagnostic = (EventKeywords)4;
            public const EventKeywords Developer = (EventKeywords)8;
        }

        private static readonly Lazy<ClientEventSource> Instance = new Lazy<ClientEventSource>(() => new ClientEventSource());

        private ClientEventSource() { }

        public static ClientEventSource Log { get { return Instance.Value; } }

        [Event(107, Message = "Debug: ", Level = EventLevel.Informational, Keywords = Keywords.Developer)]
        public void Trace(string message)
        {
            this.WriteEvent(107, message);
        }

        [Event(100, Message = "Shell loaded", Level = EventLevel.Informational)]
        public void LoadedShell()
        { 
            this.WriteEvent(100); 
        }
write logs
protected override DependencyObject CreateShell()
{
            var shell = Container.Resolve<Shell>();
            shell.Show();

            ClientEventSource.Log.LoadedShell();
            ClientEventSource.Log.Trace("Developer debug trace string");
            return shell;
}
Resulting log file
EventId : 100, Level : Informational, Message : Shell loaded, Payload : , EventName : LoadedShellInfo, Timestamp : 2014-08-15T08:28:21.2273900Z, ProcessId : 10624, ThreadId : 10548

EventId : 107, Level : Informational, Message : Debug: , Payload : [message : Developer debug string] , EventName : TraceInfo, Timestamp : 2014-08-15T08:28:21.2503900Z, ProcessId : 10624, ThreadId : 10548
Aug 18, 2014 at 9:31 PM
If you don't specify a Keywords value for an Event the Keywords is defaulted to EventKeywords.None. The meaning of None is that "No filtering on keywords is performed when the event is published".

So if you don't specify a keyword then the event will not be filtered using keywords. If you want to exclude LoadedShell by keyword then you would need to assign it a keyword.


~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Marked as answer by davidwatson on 8/20/2014 at 12:18 AM
Aug 20, 2014 at 8:19 AM
Thanks Randy that has fixed it
Dec 18, 2014 at 7:53 PM
Is there any reason the OOP service filters differently from in-process? If I use an in-process listener I get the behavior described above. If I use the OOP service the log contains only the events with the specified Keywords; none of the events with no keywords specified are included in the log.