views:

469

answers:

6

Hi, I'm trying to debug a C# application. The method:

System.Diagnostics.Debug.WriteLine("something");

should do the work, but in the Output window (set to "debug" and with all the options activated) I can't see a single line I'm trying to write. Any idea? Thanks

EDIT: I'm using VS2008

+1  A: 

Have you checked to make sure you're compiling in Debug mode? If you compile in Retail / Release mode you will see this behavior.

You should be able to see this information on Visual Studio's toolbar. There will be a combo box which will say Release or Debug. If it says Release, switch it to Debug.

In certain profile settings, this combo box will not be visible by default. You'll have to access it through the project properties page. It will be on the build / compile tab.

JaredPar
That's what I was asking in my comment, although I could have been more clear! :)
Mitch Wheat
A: 

You need to explicitly add the system's Console as a TraceListener in order for the output to appear in the console. According to Microsoft's documentation, this code should do the trick. This is C# code, but the link I provided contains examples for the other .NET languages.

using System;
using System.Data;
using System.Diagnostics;

class Test
{
    static void Main()
    {
       Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
       Debug.AutoFlush = true;
       Debug.Indent();
       Debug.WriteLine("Entering Main");
       Console.WriteLine("Hello World.");
       Debug.WriteLine("Exiting Main"); 
       Debug.Unindent();
    }
}
William Brendel
Hmmm, this doesn't work for me ..
pistacchio
Have you tried adding "#define DEBUG" to your source file?
William Brendel
also adding #define DEBUG didn't work
pistacchio
+1  A: 

Also, make sure that your Output window is set to show "Debug" output instead of something else like "Build" output.

You should see it loading all the required assemblies in the "Debug" output.

Navaar
Yes, it is in the "Debug" mode
pistacchio
+3  A: 

There's an option under Tools-Options-Debugging-General, Redirect all Output Window text to the Immediate Window. Make sure that's disabled. However, by default it isn't, so I doubt that's your issue. You can also just check your Immediate Window to see if it's outputting there.

You might also want to try resetting all your environment settings. (Tools - Import and Export Settings - Reset all settings.)

Richard Hein
This was the origin of the problem, thanks
pistacchio
A: 

Apart from the suggestions above, take a look at the project properties by right-clicking on the project name and selecting Properties. Once you have that up click on the Build tab and then the Advanced button in the lower right. Once you have the Advanced window up, take a look at the Output section and the Debug Info: setting. When you are in debug mode this should be set to full.

Alexander Kahoun
A: 

Also worth checking - right-click in the output window, and ensure "Program output" is checked.

PaulS