Trace Class - How to set Autoflush by code
c#, system.diagnostics, trace
Solution
Try adding this...
Trace.AutoFlush = true;
Problem
I would like to set the AutoFlush attribute to true, but I need to do it by code. Programmatically. I have found this how to configure the trace element and also the AutoFlush property of the Trace Class. Then I have this code to get the 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.