3

我正在使用 System.Diagnostics.EventSource 进行语义日志记录(.net 4.5)。

我想创建适当的单元测试,以确保事件实际上是用适当的内容触发的。

我怎样才能做到这一点?

测试方法示例:

[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());
}
4

0 回答 0