You need to add a Trace Listener to your code. Below is sample code that adds a TextWriterTraceListener (and don’t forget the Flush before you terminate). For more information on tracing in general, look for the topic ‘Tracing Code in an Application’ in your online .NET documentation.
//set up the listener...
System.IO.FileStream myTraceLog = new System.IO.FileStream(@'C:\myTraceLog.txt', System.IO.FileMode.OpenOrCreate);
TextWriterTraceListener myListener = new TextWriterTraceListener(myTraceLog);
..........
//output to the instance of your listener
myListener.WriteLine( 'This is some good stuff');
...........
//flush any open output before termination... maybe in an override of your form’s OnClosed
myListener.Flush();
Share with