[英]Debug.WriteLine not working
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: 在过去,也许是我现在使用的2008之前的Visual Studio版本,我会在我的VB.NET代码中做这样的事情:
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 http://screencast.com/t/YQnPb0mJcs
I'm using Visual Studio 2008. 我正在使用Visual Studio 2008。
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. 或者,您也可以使用Console.WriteLine()函数。
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. 我注意到我没有看到这个提示,所以我会说: 在你的app.config文件中,确保你的跟踪监听器中没有<clear/>
元素 。
You will effectively be clearing the list of trace listeners, including the default trace listener used for Debug statements. 您将有效地清除跟踪侦听器列表, 包括用于Debug语句的默认跟踪侦听器。
Here's what this would look like in your app.config file: 以下是app.config文件中的内容:
<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: 如果要在app.config文件中为跟踪侦听器设置占位符,则应使用以下内容:
<system.diagnostics>
<trace>
<listeners>
</listeners>
</trace>
</system.diagnostics>
在输出窗口中单击鼠标右键,确保选中“程序输出”。
Do you definitely have the DEBUG constant defined? 你肯定定义了DEBUG常量吗? 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). 检查项目属性 - > 编译 - > 高级编译选项 (DEBUG常量的复选框。如果未选中,则不会执行Debug.XXX语句)。
It should go to the output window if your app is compiled with the Debug configuration rather than the Release configuration. 如果使用Debug配置而不是Release配置编译应用程序,它应该转到输出窗口。 But instead of Debug.WriteLine()
, try using Trace.WriteLine()
(optionally with a ConsoleTraceListener
attached). 但是,不要使用Debug.WriteLine()
,而是使用Trace.WriteLine()
(可选择附加ConsoleTraceListener
)。
Some extra ideas to try or check: 尝试或检查一些额外的想法:
Check your Immediate Window . 检查您的立即窗口 。 You might have all the output redirected to it. 您可能将所有输出重定向到它。
For me this was the fact that Debug.WriteLine shows in the Immediate window, not the Output. 对我来说,这是Debug.WriteLine在立即窗口中显示而不是输出的事实。 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: 我默认安装Visual Studio 2013甚至没有显示打开立即窗口的选项,因此您必须执行以下操作:
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. 一旦你有了Ok,那你就可以进入菜单View → Other Windows并选择Immediate Window,然后就可以看到所有的调试输出。
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 :-) 不幸的是,它还显示了我在项目中没有发现的大约50个错误...也许我会再次关闭它:-)
It happens. 它发生了。 I have the similar symptom when I am developing ASP.NET MVC applications on Visual Studio 2010 web developer Express Edition. 当我在Visual Studio 2010 Web开发人员Express Edition上开发ASP.NET MVC应用程序时,我有类似的症状。 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
. 执行System.Diagnostic.Debug.Writeline
时没有输出(即使它在调试启动时运行), web.config
没有任何问题。
My workaround is: - Goto project properties--> web - In the Debugger section, check the the ASP.NET option 我的解决方法是: - 转到项目属性 - > web - 在Debugger部分中,检查ASP.NET选项
Hope this helps someone who comes across this thread. 希望这可以帮助遇到这个帖子的人。
I had a similar issue with Visual Studio 2013 and MS unit testing. 我在Visual Studio 2013和MS单元测试中遇到了类似的问题。 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. 右键单击单元测试方法并选择Run Tests,任何Debug.WriteLine调用都不会显示在立即窗口或调试输出窗口中。 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. 即使我正在测试的库和单元测试项目本身都在项目属性的构建部分中进行了DEBUG条件检查。
In order for the Debug.WriteLine statements to output anything I needed to run the unit tests by right clicking and selecting Debug Tests. 为了让Debug.WriteLine语句通过右键单击并选择Debug Tests来输出运行单元测试所需的任何内容。 Only then did I get the debug output being written to the debug output window. 只有这样我才能将调试输出写入调试输出窗口。
I was having the same problem for an ASP.NET application, and I found out that my Web.Config had the following line: 我对ASP.NET应用程序遇到了同样的问题,我发现我的Web.Config有以下几行:
<system.web>
<trace enabled="false"/>
</system.web>
Just changing it to true, and I started seeing the Debug.WriteLine
in Output
window. 只需将其更改为true,我就开始在Output
窗口中看到Debug.WriteLine
。
Make sure you press F5 to Start Debugging mode (not Ctr + F5 ). 确保按F5键启动调试模式(不是Ctr + F5 )。
F5 Starting Debugging F5开始调试
CTRL + F5 Starting Without Debugging CTRL + F5无需调试即可启动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.