为什么System.Diagnostics.Debug.WriteLine在Visual Studio 2010 C#中不起作用?
我的代码中有以下行:
System.Diagnostics.Debug.WriteLine("Title:" + title + "title[top]: " + title[top] + "title[sub]: " + title[sub]);
当我调试时,我看到它会转到这一行,但当我在Visual Studio 2010中查看输出窗口时,即使它显示“Debug”并且我使用“debug> run”运行,我也看不到任何内容。 为什么?
检查以下项目 –
-
DEBUG
选择DEBUG
模式 - 在输出窗口中选择
Debug
选项 – - 查看断点是否在代码中命中Debug.WriteLine
- 在代码的开头插入
Debug.AutoFlush = true
- 尝试检查解决方案的平台是否设置为任何CPU而不是x86(或x64)。
- 转到项目属性 – > Web – 在“调试器”部分中,检查ASP.NET选项
点#5的参考(阅读评论,它适用于那个人)
对我来说,这解决了这个问题:
System.Diagnostics.Trace.WriteLine("whatever");
(使用Trace
而不是Debug
)
在app.config文件中,确保跟踪侦听器中没有
元素。
您将有效地清除跟踪侦听器列表,包括用于Debug语句的默认跟踪侦听器。
以下是app.config文件中的内容:
对我来说,我需要这样做才能解决问题:
1. Open the project's property page 2. Under Build tab, check "Define DEBUG constant" and "Define Trace constant"
瞧!