Reputation: 1216
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.
Upvotes: 39
Views: 49772
Reputation: 121
After pulling the project off a repo the settings in the launch button were different than they ought to be. It was set to publish. If you ended up here and the very first answer doesn't work, check it.
Also using Trace instead of Debug seems to work when published is mistakenly selected.
Upvotes: 1
Reputation: 839
This issue occurred to me in a different way while deploying code to remote servers.
I already had a bunch of pre-configured build configurations in Configurations Manager. I always chose the staging environment settings while publishing. Since i stayed in debug mode in my local machine ,It never occured to me that the preconfigured build configuration also has a mode.
So do check for the config under settings- DEBUG or RELEASE and pick DEBUG
Also make sure you copy your .pdb files along with respective dlls.
Hope this helps someone
Upvotes: 0
Reputation: 11
What helped to me is selecting "Tools => Options => Projects and Solutions => Build and Run => MSBuild project build output verbosity" to "Diagnostics". After that it just started to show debug ouput in Debug block without any listeners adding. [You need at least 10 reputation to post images. Big thanks to SO for this!]
Upvotes: 1
Reputation: 1621
In case any of the others answer do not work. Try to place a break point in Debug.WriteLine
line and see if it is being hit.
In case it is not being hit the reason is because an old version of the code is being executed.
To fix this, first check this
Go to Tools-Options
Under Projects and solution -> Build and Run select "Always build" under "On Run, when projects are out of date"
And Check if the Temporary files are cleaned out. Check this SO Question
This worked for me.
If even this fails try rebooting VS. Works most of the time.
Upvotes: 1
Reputation: 376
For anyone googling: Whilst there's various answers that point to removal of the listeners in the config file also watch out for
<remove name="OPTIONSVerbHandler" />
in the section
<handlers>
As this also suppresses debug output.
Upvotes: 1
Reputation: 3613
The answer is easy. It might be that you press ctrl+F5 which means Starting Without Debugging.
Simply press F5 to Start Debugging
mode.
Upvotes: 2
Reputation: 1174
On Menu > tools > options > debugging > General:
On Project Properties > Build:
On the Output window:
Upvotes: 96
Reputation: 5936
I'm not sure anyone has mentioned this reason, but if I compile in Debug-mode and then just run the program (Ctrl + F5) instead of choosing Start Debugging (F5), I won't see the Debug.WriteLine
either.
So it isn't enough to simply compile in Debug mode, you also have to actively Debug the program and not just run it :)
Upvotes: 4
Reputation: 754565
There are two likely causes for this behavior
Debug.WriteLine
call is not in the final programThe 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
Upvotes: 36
Reputation: 2364
Debug.WriteLine("Test");
should be showing in the output window when you are in the debug mode. If you want to debug an application running (Release mode) you can use Trace and that would show in Windows events.
Upvotes: 2
Reputation: 817
I believe "Debug.WriteLine()" writes to the Listeners collection. From there you can determine where the debug information will be written. By default "Output" should be where it appears, but if you are having trouble viewing the information then create a different listener to grab the debug info.
Here is the MSDN example:
TextWriterTraceListener myWriter = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(myWriter);
Upvotes: 8