I'm using System.Diagnostics.EventSource for semantic logging (.net 4.5).
I would like to create proper unit tests to make sure that the events were actually fired with the appropriate content.
How can I do that?
Example of method to test:
[Event(ExceptionOccuredId, Message = "An {0} occured: {1} Stacktrace: {2}{3}", Keywords = Keywords.Exception, Level = EventLevel.Error)]
internal void ExceptionOccured(string typeName, string message, string stackTrace, string relatedMessages)
{
StringBuilder sb = new StringBuilder();
if (relatedMessages.Any())
{
sb.Append(string.Format(" Additional messages: {0}"));
}
this.WriteEvent(ExceptionOccuredId, typeName, message, stackTrace, sb.ToString());
}