gpt4 book ai didi

c# - 对事件 ApplicationStarted 使用未定义的关键字值 0x1。在 EnterpriseLibrary SLAB 中

转载 作者:行者123 更新时间:2023-11-30 14:29:10 27 4
gpt4 key购买 nike

我正在使用企业库 SLAB 进行日志记录但总是自从几天后我就出错了对事件 ApplicationStarted 使用未定义的关键字值 0x1。它编译正常,但就在我们尝试启用日志事件时抛出运行时错误使用以下行

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 个不同的关键字。”

“虽然 Keywords 看起来像一个枚举,但它是一个具有 System.Diagnostics.Tracing.EventKeywords 类型常量的静态类。但是就像标志一样,您需要确保将 2 的幂作为每个常量的值。 "

“如果您决定使用关键字,则必须在名为关键字嵌套类中定义要使用的关键字”

[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;
}
...
}

Tasks 和 Opcodes 同样的故事:

“您可以使用事件属性的OpcodesTasks 参数将附加信息添加到事件源记录的消息中。Opcodes 和Tasks 是使用嵌套相同名称的类,其方式与您定义关键字的方式类似”

区别是:“不需要为操作码和任务分配 2 的幂值。”并且“如果您选择定义自定义操作码,则应分配 11 或以上的整数值。”

您可以在此处阅读全文:

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

关于c# - 对事件 ApplicationStarted 使用未定义的关键字值 0x1。在 EnterpriseLibrary SLAB 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27149413/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com