Trace Class - How to install Autoflush by code

I would like to set the AutoFlush attribute to true, but I need to do this with code. Program.

I found this how to configure the trace element , as well as the AutoFlush Property of the Trace class.

Then I have this code to get 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; } 

How can I set the AutoFlush property to true inside this code?

Thanks.

+4
source share
1 answer

Try to add this ...

 Trace.AutoFlush = true; 
+4
source

All Articles