vb.net Debug.WriteLine 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1370449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debug.WriteLine not working
提问by Chad
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。
采纳答案by Dan Esparza
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/>
elementin 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>
回答by JonnyD
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() 函数。
回答by PaulS
Right-click in the output window, and ensure "Program output" is checked.
右键单击输出窗口,并确保选中“程序输出”。
回答by Hamish Smith
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).
您确定定义了 DEBUG 常量吗?检查项目属性 ->编译->高级编译选项(DEBUG 常量有一个复选框。如果未选中,则不会执行 Debug.XXX 语句)。
回答by Joel Coehoorn
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).
如果您的应用程序是使用 Debug 配置而不是 Release 配置编译的,它应该转到输出窗口。但是,而不是Debug.WriteLine()
尝试使用Trace.WriteLine()
(可选地ConsoleTraceListener
附加)。
回答by Mehmet Aras
Some extra ideas to try or check:
一些额外的想法可以尝试或检查:
- Put a breakpoint before Debug.WriteLine and see what's in System.Diagnostics.Trace.Listenerscollection. 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 DebugViewthat 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.
- 在 Debug.WriteLine 之前放置一个断点并查看System.Diagnostics.Trace.Listeners集合中的内容。您应该会看到DefaultTraceListener。如果你什么都没看到,那么就没有人在听,这就是问题。
- 是否有可能在配置文件或代码中的某处清除/修改跟踪侦听器?
- 您是否在 Visual Studio 中安装了任何包或加载项?还是使用第三方库?
- 你能看到 VS 之外的调试信息吗?有一个名为DebugView的 SysInternals 应用程序,用于监视和显示系统中的调试输出。运行该工具,然后运行您的应用程序。您应该会在 DebugView 中看到您的调试消息。至少您会知道您的应用程序正在输出调试消息,但 VS 似乎没有在监听。
- 您是否浏览了输出窗口的内容以查看是否报告了任何异常或错误。您的调试输出不在那里,但其中可能有一些可以提供一些线索的东西。
回答by Josh Weatherly
Check your Immediate Window. You might have all the output redirected to it.
检查您的即时窗口。您可能已将所有输出重定向到它。
回答by Liam
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:
对我来说,这是 Debug.WriteLine 显示在立即窗口中的事实,而不是输出。默认情况下,我安装的 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 Windowsand select the Immediate Window and hey presto all of the debug output can be seen.
确定后,您可以转到菜单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 个我在我的项目中不知道的错误......也许我会再次关闭它:-)
回答by Ozair Kafray
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,然后我开始看到Debug.WriteLine
inOutput
窗口。