Thursday, October 22, 2009

Redirecting Tracing or Debugging output.

Attaching Visual Studio IDe to the application for viewing debugging information can turn out to be quite troubleesome, especially when dealing with large applications. In such cases, as developer, one would like to redirect the debugging information to a external file without having to attach the IDE.

Following code verify whether you are running an exe build using debug mode and then redirect the output to a external file.

#if (DEBUG)
TextWriterTraceListener tr2 = new TextWriterTraceListener (System.IO.File.CreateText ("DebuggerLog.txt"));

The output can be redirected to Console using ConsoleTraceListner.