Trace.Close();
var myTraceListener = new MyTraceListener(); Trace.Listeners.Add(myTraceListener); // ... Trace.Close();This example creates a custom trace listener and adds it to the list of trace listeners. After writing data to the trace listener, the Trace.Close() method is called to ensure that any remaining data is flushed to the listener and that the stream is properly closed. The Trace.Close() method is part of the System.Diagnostics namespace, which is included in the .NET Framework class library.