Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug.WriteLine shows nothing

Tags:

c#

debugging

When using

using System.Diagnostics; 

and

Debug.WriteLine("Test"); 

having run the application, no "Test" can be seen in output. But if I use the msgbox function instead, the msgbox pops up, so the line is reached.

Am I looking in the wrong window or what do I have to change?

I am using VC# Express.

like image 317
Zurechtweiser Avatar asked Feb 20 '12 23:02

Zurechtweiser


People also ask

How do I enable debug WriteLine?

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 Tools → Options → Debugging → General. To display "Tools → Options → Debugging", check the box next to "Tools → Options → Show All Settings".

What does debug WriteLine do?

Writes information about the debug to the trace listeners in the Listeners collection.

How do I check Output of console WriteLine?

Example: Debug. WriteLine("Hello World"); Finally, press Ctrl+Alt+O to open the output window. Your text will be printed there.

How do I show debug Output in Visual Studio?

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.


2 Answers

On Menu > tools > options > debugging > General:

  • Ensure "Redirect all output window text to the immediate window" is NOT checked

On Project Properties > Build:

  • Configuration: Debug
  • "Define DEBUG constant" is checked
  • "Define TRACE constant" is checked

On the Output window:

  • Show output from: Debug
  • Right-click in the output window and ensure "Program output" is checked
like image 192
Guillermo Hernandez Avatar answered Oct 05 '22 12:10

Guillermo Hernandez


There are two likely causes for this behavior

  • The application is being compiled in Release mode and the Debug.WriteLine call is not in the final program
  • There is no trace listener in the program and hence nothnig to output the message

The easiest way to diagnose this is to change the code to

#if DEBUG Console.WriteLine("the message"); #endif 

If it prints then you have an issue with the trace listeners, else you're compiling in Release

like image 41
JaredPar Avatar answered Oct 05 '22 13:10

JaredPar