Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TraceSource - set autoflush to true without config file?

Tags:

c#

.net

I don't see autoflush option on TraceSource like there is for Trace.
Is there a way to autoflush without having to flush manually after each write?

BTW I'm using TextWriterTraceListener as my trace source listener and not using config xml.

like image 421
erotavlas Avatar asked Jun 11 '14 21:06

erotavlas


1 Answers

Internally TraceSource uses AutoFlush setting of Trace class. E.g. sources of TraceSource.TraceEvent method:

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 need to do, is set Trace.AutoFlush to true. BTW same is stated in MSDN:

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

like image 138
Sergey Berezovskiy Avatar answered Nov 18 '22 14:11

Sergey Berezovskiy