Redirecting log output with TraceListeners

suggest change

You can redirect the debug output to a text file by adding a TextWriterTraceListener to the Debug.Listeners collection.

public static void Main(string[] args)
{
    TextWriterTraceListener myWriter = new TextWriterTraceListener(@"debug.txt");
    Debug.Listeners.Add(myWriter);
    Debug.WriteLine("Hello");
		myWriter.Flush();
}

You can redirect the debug output to a console application’s out stream using a ConsoleTraceListener.

public static void Main(string[] args)
{
    ConsoleTraceListener myWriter = new ConsoleTraceListener();
    Debug.Listeners.Add(myWriter);
    Debug.WriteLine("Hello");
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents