可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
In the past, perhaps versions of Visual Studio prior to the 2008 that I am using now, I would do something like this in my VB.NET code:
System.Diagnostics.Debug.WriteLine("Message")
..and the output would go to the output window.
Now it doesn't. Something must first apparently be enabled.
If this involves "attaching a debugger", please explain how to do it. It seems to me that it should just work without too much of a fuss.
Here's a video explaining the issue in real time and showing you all my settings:
http://screencast.com/t/YQnPb0mJcs
I'm using Visual Studio 2008.
回答1:
All good suggestions. I noticed that I don't see this tip mentioned, so I'll say it: 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. It looks so innocent -->
<clear/>
</listeners>
</trace>
</system.diagnostics>
If you want to have a placeholder for trace listeners in your app.config file, you should instead use something like this:
<system.diagnostics>
<trace>
<listeners>
</listeners>
</trace>
</system.diagnostics>
回答2:
Check to see if the "Redirect all Output Window text to the Immediate Window" is checked under Tools -> Options -> Debugging -> General.
Alternatively, you can use the Console.WriteLine() function as well.
回答3:
Right-click in the output window, and ensure "Program output" is checked.
回答4:
Do you definitely have the DEBUG constant defined? Check under project properties -> Compile -> Advanced Compile Options (there's a checkbox for the DEBUG constant. If it isn't checked, your Debug.XXX statements will not be executed).
回答5:
It should go to the output window if your app is compiled with the Debug configuration rather than the Release configuration. But instead of Debug.WriteLine()
, try using Trace.WriteLine()
(optionally with a ConsoleTraceListener
attached).
回答6:
Some extra ideas to try or check:
- Put a breakpoint before Debug.WriteLine and see what's in System.Diagnostics.Trace.Listeners collection. You should see DefaultTraceListener. If you don't see anything, then no one is listening and that's problem.
- Is it possible that the trace listeners being cleared/modified somewhere such as in config file or in the code?
- Have you installed any package or add-in to Visual Studio? or using a third-party library?
- Can you see debug messages outside of VS? There is a SysInternals application called DebugView that monitors and shows debug output in your system. Run that tool and then run your application. You should see your debug message in DebugView. At least you will know that your application is outputting debug messages but VS does not seem to be listening.
- Have you gone through the contents of the output window to see if there is any exception or error being reported. Your debug output is not there but there might be somethings in there that can provide some clues.
回答7:
Check your Immediate Window. You might have all the output redirected to it.
回答8:
For me this was the fact that Debug.WriteLine shows in the Immediate window, not the Output. My installation of Visual Studio 2013 by default doesn't even show an option to open the Immediate window, so you have to do the following:
Select Tools → Customize
Commands Tab
View | Other Windows menu bar dropdown
Add Command...
The Immediate option is in the Debug section.
Once you have Ok'd that, you can go to menu View → Other Windows and select the Immediate Window and hey presto all of the debug output can be seen.
Unfortunately for me it also showed about 50 errors that I wasn't aware of in my project... maybe I'll just turn it off again :-)
回答9:
I was having the same problem for an ASP.NET application, and I found out that my Web.Config had the following line:
<system.web>
<trace enabled="false"/>
</system.web>
Just changing it to true, and I started seeing the Debug.WriteLine
in Output
window.
回答10:
I had a similar issue with Visual Studio 2013 and MS unit testing. Right clicking on a unit test method and selecting Run Tests any Debug.WriteLine calls would not show up in either the immediate window or the debug output window. Even though the library I was testing and the unit test project itself both had DEBUG conditional checked in the build section of there project properties.
In order for the Debug.WriteLine statements to output anything I needed to run the unit tests by right clicking and selecting Debug Tests. Only then did I get the debug output being written to the debug output window.
回答11:
It happens. I have the similar symptom when I am developing ASP.NET MVC applications on Visual Studio 2010 web developer Express Edition. The execution doesn't break at the breakpoint. There is no output when it executes System.Diagnostic.Debug.Writeline
(even though it runs with debug start), and there is nothing wrong with web.config
.
My workaround is:
- Goto project properties--> web
- In the Debugger section, check the the ASP.NET option
Hope this helps someone who comes across this thread.
回答12:
I had the same problem in Visual Studio Express 2010. I fresh installed on a debug machine and none of the suggestions worked. I ended up using NLog and logging to a text file as a workaround.
回答13:
Make sure you press F5 to Start Debugging mode (not Ctr+F5).
F5 Starting Debugging
CTRL+F5 Starting Without Debugging