配置文件:
<system.diagnostics>
<trace>
<listeners>
<add name="Console" type="System.Diagnostics.ConsoleTraceListener" initializeData="false"></add>
<add name="Text" type="System.Diagnostics.TextWriterTraceListener" initializeData="D:\uat\logs\bifit.log" traceOutputOptions="DateTime"></add>
</listeners>
</trace>
</system.diagnostics>
代码:
static void Main(string[] args)
{
try
{
Trace.WriteLine("Running BiFit Test Server.");
}
}
我可以在控制台窗口中看到文本。并且文件已创建,但它是空的。 我记得某处有类似 Autoflush 属性的东西?
最佳答案
你没有记错 - 它是在 trace
上定义的元素:
<trace autoflush="true">
...
</trace>
autoflush - Optional attribute. Specifies whether the trace listeners automatically flush the output buffer after every write operation.
关于c# - TextWriterTraceListener 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4345952/