gpt4 book ai didi

c# - TraceSource - 在没有配置文件的情况下将 autoflush 设置为 true?

转载 作者:太空狗 更新时间:2023-10-30 01:04:16 24 4
gpt4 key购买 nike

我没有在 TraceSource 上看到 autoflush 选项,就像 Trace 一样。
有没有一种方法可以自动刷新而无需在每次写入后手动刷新?

顺便说一句,我使用 TextWriterTraceListener 作为我的跟踪源监听器,而不是使用配置 xml。

最佳答案

内部 TraceSource 使用 Trace 类的 AutoFlush 设置。例如。 sources TraceSource.TraceEvent 方法:

for (int j = 0; j < this.listeners.Count; j++)
{
TraceListener listener = this.listeners[j];
listener.TraceEvent(eventCache, this.Name, eventType, id, format, args);
if (Trace.AutoFlush)
{
listener.Flush();
}
}

因此,您需要做的就是将 Trace.AutoFlush 设置为 true。顺便说一句,在 MSDN 中也有说明:

The trace listeners use the values of the Trace class properties Indent, IndentSize, and AutoFlush to format trace output.

关于c# - TraceSource - 在没有配置文件的情况下将 autoflush 设置为 true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24172868/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com