簡體   English   中英

對事件ApplicationStarted使用未定義的關鍵字值0x1。在EnterpriseLibrary SLAB中

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

我正在使用Enterprise Library SLAB進行日志記錄,但總是因為我正在收到錯誤的日期錯誤使用未定義的關鍵字值0x1用於事件ApplicationStarted。 它正在編譯正常但是當我們嘗試使用以下行啟用日志事件時拋出運行時錯誤

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

這是我的事件來源

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

“每個關鍵字值都是一個64位整數,它被視為一個位數組,使您可以定義多達64個不同的關鍵字。”

“雖然關鍵字看起來像一個枚舉,但它是一個靜態類,其常量類型為System.Diagnostics.Tracing.EventKeywords。但就像使用標志一樣,你需要確保為每個常量分配2的冪。”

“如果您決定使用關鍵字,則必須定義將在名為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;
    }
...
}

與任務和操作碼相同的故事:

“您可以使用Event屬性的OpcodesTasks參數向事件源記錄的消息添加其他信息。操作碼和任務是使用相同名稱的 嵌套類定義的,其方式與定義關鍵字的方式類似”

不同之處在於:“不需要為操作碼和任務分配值為2的冪。” 並且“如果您選擇定義自定義操作碼,則應指定11或更大的整數值。”

你可以在這里閱讀全文:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM