【发布时间】:2017-09-10 22:04:30
【问题描述】:
我的 web.config 文件中有以下代码:
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextWriterOutput.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
在我的代码后面的某处:
System.Diagnostics.Trace.WriteLine("From the trace");
运行应用程序后,TextWriterOutput.log 文件创建成功,但为空白。但是,在将 autoflush 属性更改为 true 后,跟踪写入 TextWriterOutput.log。
我还注意到我可以使用
使跟踪写入 TextWriteOutput.logSystem.Diagnostics.Trace.Flush();
而不是将autoflush属性修改为true。
我在 https://msdn.microsoft.com/en-us/library/system.diagnostics.trace.flush(v=vs.110).aspx 但这对我来说没有意义。为什么跟踪不能立即写入输出文件?谁能用简单的话解释为什么?
【问题讨论】:
标签: c# asp.net asp.net-mvc trace