为什么System.Diagnostics.Debug.WriteLine在Visual Studio 2010 C#中不起作用?

29 c# debugging asp.net-mvc visual-studio-2010 visual-studio

我的代码中有以下行:

System.Diagnostics.Debug.WriteLine("Title:" + title + "title[top]: " + title[top] + "title[sub]: " + title[sub]);
Run Code Online (Sandbox Code Playgroud)

当我调试时,我看到它会转到这一行,但当我在Visual Studio 2010中查看输出窗口时,即使它显示"Debug"并且我使用"debug> run"运行,我也看不到任何内容.为什么?

Par*_*ram 19

检查以下项目 -

  1. DEBUG 调试时选择模式
  2. Debug 选项在输出窗口中选择 - 在此输入图像描述
  3. 查看断点是否在代码中命中Debug.WriteLine
  4. Debug.AutoFlush = true在代码的开头插入
  5. 尝试检查解决方案的平台是否设置为任何CPU而不是x86(或x64).
  6. 转到项目属性 - > Web - 在"调试器"部分中,选中"ASP.NET"选项

点#5的参考(阅读评论,它适用于那个人)

  • 第4点似乎解决了这个问题.非常感谢. (3认同)

Al *_*ath 13

对我来说,这解决了这个问题:

System.Diagnostics.Trace.WriteLine("whatever");
Run Code Online (Sandbox Code Playgroud)

(用来Trace代替Debug)


Roh*_*ats 7

在app.config文件中,确保<clear/>跟踪侦听器中没有元素.

您将有效地清除跟踪侦听器列表,包括用于Debug语句的默认跟踪侦听器.

以下是app.config文件中的内容:

<system.diagnostics>
    <trace>
      <listeners>
          <!-- This next line is the troublemaker. If it is there delete it-->
          <clear/>
      </listeners>
    </trace>
  </system.diagnostics>
Run Code Online (Sandbox Code Playgroud)


Jus*_*Pup 6

对我来说,我需要这样做来解决问题:

1. Open the project's property page
2. Under Build tab, check "Define DEBUG constant" and "Define Trace constant"
Run Code Online (Sandbox Code Playgroud)

瞧!