Use of undefined keyword value 0x1 for event ApplicationStarted. in EnterpriseLibrary SLAB

1.5k views Asked by At

I am using Enterprise Library SLAB for Logging but always since coupel of days I am getting error Use of undefined keyword value 0x1 for event ApplicationStarted. It is compiling fine but throwing runtime error just when we try to enable log event using following line

listener.EnableEvents(Logger.Log, EventLevel.LogAlways, Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Keywords.All);

Here is my eventsource

public static readonly Logger Log = new Logger();
        [Event(100, Level = EventLevel.Informational, Keywords = Keywords.Application, Task = Tasks.ApplicationStarted, Opcode = Opcodes.Start, Version = 1)]
        public void ApplicationStarted()
        {
            if (this.IsEnabled(EventLevel.Informational, Keywords.Application))
            {
                this.WriteEvent(100);
            }
        }

        [Event(101, Level = EventLevel.Informational, Keywords = Keywords.Application, Task = Tasks.ApplicationClosed, Opcode = Opcodes.Closed, Version = 1)]
        public void ApplicationClosed()
        {
            if (this.IsEnabled(EventLevel.Informational, Keywords.Application))
            {
                this.WriteEvent(101);
            }
        }
1

There are 1 answers

2
Alexander S. On

"Each keyword value is a 64-bit integer, which is treated as a bit array enabling you to define up to 64 different keywords."

"Although Keywords looks like an enumeration, it’s a static class with constants of type System.Diagnostics.Tracing.EventKeywords. But just as with flags, you need to make sure you assign powers of two as the value for each constant."

"If you decide to use keywords, you must define the keywords you will use in a nested class called Keywords"

[EventSource(Name = "MyCompany")]
public class MyCompanyEventSource : 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;
    }
...
}

The same story with the Tasks and Opcodes:

"You can use the Opcodes and Tasks parameters of the Event attribute to add additional information to the message that the event source logs. The Opcodes and Tasks are defined using nested classes of the same name in a similar way to how you define Keywords"

Differences are: "Opcodes and Tasks don’t need to be assigned values that are powers of two." And "If you choose to define custom opcodes, you should assign integer values of 11 or above."

You can read full article here:

https://msdn.microsoft.com/en-us/library/dn440729.aspx