Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does System.Diagnostics.Debug.WriteLine not work in Visual Studio 2010 C#?

People also ask

How do I check my System diagnostics Debug WriteLine?

Diagnostics. Debug. WriteLine will display in the output window ( Ctrl + Alt + O ), you can also add a TraceListener to the Debug.

What is Debug WriteLine in C#?

"Writes information about the debug to the trace listeners in the Listeners collection." c# visual-studio.

Where does System diagnostics trace WriteLine write to?

WriteLine(String) Writes a message to the trace listeners in the Listeners collection.

How do I get console WriteLine output in Visual Studio?

In Visual Studio uppermost menu choose Debug > Windows > Output. It shows all Console. WriteLine("Debug MyVariable: " + MyVariable) when you get to them. Set breakpoint before, debug, and then use F11 to step through code line by line.


Check following items -

  1. DEBUG mode is selected while debugging
  2. Debug option is selected in Output window - enter image description here
  3. See if breakpoint is hitting Debug.WriteLine in code
  4. Insert Debug.AutoFlush = true at the beginning of code
  5. Try checking if Platform for the solution is set to Any CPU and not x86 (or x64).
  6. Goto Project Properties--> Web - In the Debugger section, check the the ASP.NET option

Reference for Point #5 (Read the comment, It worked for that guy)


For me, this solved the problem:

System.Diagnostics.Trace.WriteLine("whatever");

(using Trace instead of Debug)


In your app.config file, make sure you don't have a <clear/> element in your trace listeners.

You will effectively be clearing the list of trace listeners, including the default trace listener used for Debug statements.

Here's what this would look like in your app.config file:

<system.diagnostics>
    <trace>
      <listeners>
          <!-- This next line is the troublemaker. If it is there delete it-->
          <clear/>
      </listeners>
    </trace>
  </system.diagnostics>

For me, I needed to do this to solve the problem:

1. Open the project's property page
2. Under Build tab, check "Define DEBUG constant" and "Define Trace constant"

Voila!


I had the same problem. Using Trace.WriteLine and checking "Define DEBUG constant" did not work for me.

I noticed that the output messages were found in Immediate window, instead of Output window.

Then I unchecked "Redirect all Output Window text to the Immediate Window" option in tools and solved my problem.