Logo Questions Linux Laravel Mysql Ubuntu Git Menu

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

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

        [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))
like image 671
Abhi Avatar asked Mar 18 '23 19:03


1 Answers

"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:


like image 79
Alexander S. Avatar answered Mar 21 '23 07:03

Alexander S.