예제 #1
0
 public void Test_Error()
 {
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     TraceSource traceSource = new TraceSource("Test", SourceLevels.All);
     traceSource.Listeners.Add(new TextWriterTraceListener(sw));
     var traceLogger = new TraceLogger(new IMessageFormatter[] { new StringMessageFormatterMock() }, traceSource);
     var message = "Test_Error";
     traceLogger.Error(message);
     Assert.AreEqual("Test Error: 2 : " + message + "\r\n", sb.ToString());
 }
예제 #2
0
 public void Test_Error_Exception()
 {
     //输出到Console
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     TraceSource traceSource = new TraceSource("Test", SourceLevels.All);
     traceSource.Listeners.Add(new TextWriterTraceListener(sw));
     var traceLogger = new TraceLogger(new IMessageFormatter[] { new StringMessageFormatterMock() }, traceSource);
     var message = "Test_Error_Exception";
     Exception ex;
     try
     {
         throw new Exception("Test_Error_Exception");
     }
     catch (Exception e)
     {
         ex = e;
     }
     traceLogger.Error(message, ex);
     Assert.AreEqual("Test Error: 2 : " + message + "\r\n" + ex.Message + "\r\n", sb.ToString());
 }