TraceListener不输出所有跟踪

时间:2016-02-10 19:37:40

标签: c# trace tracelistener

我已使用以下TraceListener

配置了我的WPF应用程序
<system.diagnostics>
  <trace autoflush="true" indentsize="4">
    <listeners>
      <add name="myListener" type="MyApp.RollTraceListener, MyApp" initializeData="myapplication.log" />
      <add name="listener" type="System.Diagnostics.TextWriterTraceListener" initializeData="application.log" />
    </listeners>
  </trace>
</system.diagnostics>

Release中,定义了TRACE常量,但两个文件中的内容不同。我错过了什么?

public class RollTraceListener : System.Diagnostics.TraceListener
{
   string fileName;
   DateTime startDate;
   StreamWriter traceWriter; 

   public RollTraceListener(string fileName)
   {
      this.fileName = fileName;
      this.startDate = System.DateTime.Now;
      var stream = new FileStream(this.fileName, FileMode.Create);
      traceWriter = new StreamWriter(stream);
   }

   public override void Write(string value)
   {
      traceWriter.Write(value);
   }

   public override void WriteLine(string value)
   {
      traceWriter.WriteLine(value);
   }

   protected override void Dispose(bool disposing)
   {
      if(disposing)
      {
         traceWriter.Flush();
         traceWriter.Close();
      }
   }
}

通常,如果我只是写System.Diagnostics.Trace.WriteLine("Hello World!");,那么该行存在于application.log中,但不存在于myapplication.log中

0 个答案:

没有答案