user1464139
user1464139

Reputation:

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

I have the following line in my code:

System.Diagnostics.Debug.WriteLine("Title:" + title + "title[top]: " + title[top] + "title[sub]: " + title[sub]);

When I debug I see it going to this line, but when I look at the output window in Visual Studio 2010 I don't see anything even though it shows for "Debug" and I ran using "debug > run". Why?

Upvotes: 38

Views: 53612

Answers (8)

Katsutoshi Hayashida
Katsutoshi Hayashida

Reputation: 599

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 the Immediate Window instead of the Output Window.

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

Upvotes: 6

CFL_Jeff
CFL_Jeff

Reputation: 2719

Make sure you're not using "Start Without Debugging (Ctrl + F5)"

Start Without Debugging Button

Upvotes: 1

AdvApp
AdvApp

Reputation: 1170

Also, check that the "Program Output" is checked in the Messages selection (right-click in Output window.

Upvotes: 1

Lucio Flavio
Lucio Flavio

Reputation: 101

Using "System.Diagnostics.Debug.WriteLine" I've output in the Immediate Window :-O

Upvotes: 1

JustAPup
JustAPup

Reputation: 1780

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!

Upvotes: 7

Al Lelopath
Al Lelopath

Reputation: 6778

For me, this solved the problem:

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

(using Trace instead of Debug)

Upvotes: 21

Parag Meshram
Parag Meshram

Reputation: 8521

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)

Upvotes: 22

Rohit Vats
Rohit Vats

Reputation: 81313

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>

Upvotes: 8

Related Questions