Redirect the output of Debug.WriteLine()

  • Thread starter Thread starter Frank Rizzo
  • Start date Start date
F

Frank Rizzo

Is there anyway to transparently redirect the output of the
Debug.WriteLine statement from the Debug window to something else such
as a console or a file?

Thanks
 
Frank Rizzo said:
Is there anyway to transparently redirect the output of the
Debug.WriteLine statement from the Debug window to something else such as
a console or a file?

Thanks

TextWriterTraceListener[] listeners = new TextWriterTraceListener[] {
new TextWriterTraceListener("C:\\debug.txt"),
new TextWriterTraceListener(Console.Out)
};

Debug.Listeners.AddRange(listeners);

Debug.WriteLine("Some Value", "Some Category");
Debug.WriteLine("Some Other Value");

HTH,
Mythran
 
Mythran said:
Frank Rizzo said:
Is there anyway to transparently redirect the output of the
Debug.WriteLine statement from the Debug window to something else such as
a console or a file?

Thanks

TextWriterTraceListener[] listeners = new TextWriterTraceListener[] {
new TextWriterTraceListener("C:\\debug.txt"),
new TextWriterTraceListener(Console.Out)
};

Debug.Listeners.AddRange(listeners);

Debug.WriteLine("Some Value", "Some Category");
Debug.WriteLine("Some Other Value");

HTH,
Mythran

Another note, you can create your own class and inherit from the
TraceListener class to add more functionality to the trace listeners. For
example, you could create a SqlTraceListener that would output to a Sql
Server instead of a stream....just a thought :)

HTH,
Mythran
 
Mythran said:
Is there anyway to transparently redirect the output of the
Debug.WriteLine statement from the Debug window to something else
such as a console or a file?

Thanks


TextWriterTraceListener[] listeners = new TextWriterTraceListener[] {
new TextWriterTraceListener("C:\\debug.txt"),
new TextWriterTraceListener(Console.Out)
};

Debug.Listeners.AddRange(listeners);

Debug.WriteLine("Some Value", "Some Category");
Debug.WriteLine("Some Other Value");

HTH,
Mythran

Another note, you can create your own class and inherit from the
TraceListener class to add more functionality to the trace listeners.
For example, you could create a SqlTraceListener that would output to a
Sql Server instead of a stream....just a thought :)

HTH,
Mythran
That is sweet. Thank you.
 
Back
Top