Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does System.Diagnostics.Debug.Write output appear?

Tags:

c#

debugging

People also ask

How do I show debug output?

To see the debug output window, in Microsoft Visual Studio, click View, click Other Windows, and then click Output. You can view the debug output in this window only if the debugger is attached to the process that is writing to the output window.

What is debug WriteLine?

WriteLine(String) Writes a message followed by a line terminator to the trace listeners in the Listeners collection. WriteLine(Object) Writes the value of the object's ToString() method to the trace listeners in the Listeners collection.

Where does console WriteLine go C#?

It goes to the console (standard output) or to the stream that the console is set to.

Which namespace does the trace and debug function belong?

NET Framework Class Library namespace System.


While debugging System.Diagnostics.Debug.WriteLine will display in the output window (Ctrl+Alt+O), you can also add a TraceListener to the Debug.Listeners collection to specify Debug.WriteLine calls to output in other locations.

Note: Debug.WriteLine calls may not display in the output window if you have the Visual Studio option "Redirect all Output Window text to the Immediate Window" checked under the menu ToolsOptionsDebuggingGeneral. To display "ToolsOptionsDebugging", check the box next to "ToolsOptionsShow All Settings".


As others have pointed out, listeners have to be registered in order to read these streams. Also note that Debug.Write will only function if the DEBUG build flag is set, while Trace.Write will only function if the TRACE build flag is set.

Setting the DEBUG and/or TRACE flags is easily done in the project properties in Visual Studio or by supplying the following arguments to csc.exe

/define:DEBUG;TRACE


You need to add a TraceListener to see them appear on the Console.

TextWriterTraceListener writer = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(writer);

They also appear in the Visual Studio Output window when in Debug mode.


While you are debugging in Visual Studio, display the "Output" window (View->Output). It will show there.


The Diagnostics messages are displayed in the Output Window.