c# – 跟踪类 – 如何通过代码设置Autoflush
作者:互联网
我想将AutoFlush属性设置为true,但我需要通过代码来完成.编程.
我发现了这个how to configure the trace element以及Trace Class的AutoFlush property.
然后我有这个代码来获取TraceSource:
private static TraceSource GetTraceSource()
{
var ts = new TraceSource("TraceManager")
{
Switch =
{
Level = SourceLevels.All
}
};
ts.Attributes.Add("AutoFlush", "true");
ts.Listeners.Remove("Default");
var file = System.IO.Path.GetTempPath() + @"\MyApplication.log";
var textListener = new TextWriterTraceListener(file)
{
Filter = new EventTypeFilter(SourceLevels.All)
};
ts.Listeners.Add(textListener);
return ts;
}
如何在此代码中将AutoFlush属性设置为true?
谢谢.
解决方法:
尝试添加此…
Trace.AutoFlush = true;
标签:c,trace,system-diagnostics 来源: https://codeday.me/bug/20190625/1285287.html