我已使用以下TraceListener
<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中