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, see Tracing Code in an Application in the Visual Basic and Visual C# Concepts.
using System.Diagnostics;
using System.IO;
// set up listener
string filename = @"C:\listener.txt";
FileStream traceLog = new FileStream( filename, FileMode.OpenOrCreate );
TextWriterTraceListener listener = new TextWriterTraceListener( traceLog );
// output to listener
listener.WriteLine( "Trace message here" );
// flush any open output before termination
// maybe in an override of Form.OnClosed
listener.Flush();
Contributed from George Shepherd's Windows Forms FAQ