Set autoflush to true without config file?

I do not see autoflush options on TraceSource, for example, for Trace.
Is there an autoflush way without the need for manual manual control after each recording?

BTW I use TextWriterTraceListener as my trace source listener and do not use config xml.

+4
source share
3 answers

Inside the class setting is TraceSourceused . For instance. method sources :AutoFlushTraceTraceSource.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();
    }
}

So, all you have to do is set Trace.AutoFlushto true. BTW is also listed on MSDN :

Trace , IndentSize AutoFlush .

+5

, !

TextWriterTraceListener listener = new TextWriterTraceListener(@"C:\MyFolder\Temp.log");
StreamWriter sw = listener.Writer as StreamWriter;
if (sw != null) sw.AutoFlush = true;
0
StreamWriter sw = File.AppendText(path);

traceSource.Listeners.Add(new TextWriterTraceListener(sw) { TraceOutputOptions = TraceOptions.DateTime });
0
source

Source: https://habr.com/ru/post/1544230/


All Articles