gpt4 book ai didi

logging - 语义记录 : An item with the same key has already been added

转载 作者:行者123 更新时间:2023-12-04 20:08:15 25 4
gpt4 key购买 nike

我正在尝试使用新的语义应用程序块进行日志记录。根据 MSDN,我有使用测试方法检查 EventSource

EventSourceAnalyzer.InspectAll(MyEventSource.Log);

但是当我运行这个测试时,我收到了错误
An item with the same key has already been added 

如果我们使用相同的事件 ID,通常我们会得到这个错误,但我对每种方法使用不同的 EventID。下面是我的事件源类
EventSource(Name = "SLAB_1.1.1403.1")]
public class MyEventSource : 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;
}

public class Tasks
{
public const EventTask Page = (EventTask)1;
public const EventTask DBQuery = (EventTask)2;
}

private static MyEventSource _log = new MyEventSource();
private MyEventSource() { }
public static MyEventSource Log { get { return _log; } }

[Event(1, Message = "Application Failure: {0}",
Level = EventLevel.Critical, Keywords = Keywords.Diagnostic)]
internal void Failure(string message)
{
if (this.IsEnabled(EventLevel.Critical, Keywords.Diagnostic))
{
this.WriteEvent(1, message);
}
}

[Event(2, Message = "Application Failure1: {0}",
Level = EventLevel.Critical, Keywords = Keywords.Diagnostic)]
internal void Failure(string message, string exception)
{
if (this.IsEnabled(EventLevel.Critical, Keywords.Diagnostic))
{
this.WriteEvent(2, message, exception);
}
}

[NonEvent]
internal void Failure(string message, Exception ex)
{
if (this.IsEnabled(EventLevel.Critical, Keywords.Diagnostic))
{
Failure(message, ex.ToString());
}
}
}

最佳答案

方法名称是键,因此由于您有两个名为 Failure 的方法,即使您有不同的参数列表,SLAB 基础结构也会将方法名称作为键添加到字典中。将您的其中一种故障方法重命名为 Failure2 或类似名称以解决此问题。

关于logging - 语义记录 : An item with the same key has already been added,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22817215/

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