Im trying to use new semantic application block for logging. As per MSDN i have test method which inspects the EventSource using
EventSourceAnalyzer.InspectAll(MyEventSource.Log);
But when i run this test i'm getting error
An item with the same key has already been added
Usually we get this error if we use same event id, but im using different EventID for each method. Below is my event source class
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());
}
}
}