Using the undefined value of the keyword 0x1 for the ApplicationStarted event. at EnterpriseLibrary SLAB

I am using SLAB for application library for logging but always starting from dome of days I get the error Using undefined keyword 0x1 for ApplicationStarted event. It compiles fine but throws a runtime error when we try to enable the log event using the following line

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

;

Here is my eventource

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

      

+3


source to share


1 answer


"Each keyword value is a 64-bit integer that is treated as a bit-bit, allowing up to 64 different keywords to be defined."

"Although the keywords appear to be an enumeration, this is a static class with constants of type System.Diagnostics.Tracing.EventKeywords. But just like flags, you need to make sure you assign permissions two as the value for each constant."

"If you choose to use keywords, you must define the keywords that you will use in the nested Keywords class . "

[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 Tasks and Codes:



"You can use the Opcodes and Tasks parameters of the Event attribute to add additional information to the message that the event log sends. Codes and tasks are defined using nested classes of the same name in a similar way to how you define keywords

Differences: "Opcodes and Tasks should not be assigned values ​​equal to two." And "If you choose to define custom opcodes, you must assign integer values ​​11 or higher."

You can read the full article here:

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

+4


source







All Articles