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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13000507/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:17:11  来源:igfitidea点击:

Why does System.Diagnostics.Debug.WriteLine not work in Visual Studio 2010 C#?

c#asp.net-mvcvisual-studio-2010visual-studiodebugging

提问by

I have the following line in my code:

我的代码中有以下行:

System.Diagnostics.Debug.WriteLine("Title:" + title + "title[top]: " + title[top] + "title[sub]: " + title[sub]);

When I debug I see it going to this line, but when I look at the output window in Visual Studio 2010 I don't see anything even though it shows for "Debug" and I ran using "debug > run". Why?

当我调试时,我看到它转到这一行,但是当我查看 Visual Studio 2010 中的输出窗口时,我看不到任何东西,即使它显示为“调试”并且我使用“调试>运行”运行。为什么?

采纳答案by Parag Meshram

Check following items -

检查以下项目 -

  1. DEBUGmode is selected while debugging
  2. Debugoption is selected in Output window - enter image description here
  3. See if breakpoint is hitting Debug.WriteLine in code
  4. Insert Debug.AutoFlush = trueat the beginning of code
  5. Try checking if Platform for the solution is set to Any CPU and not x86 (or x64).
  6. Goto Project Properties--> Web - In the Debugger section, check the the ASP.NET option
  1. DEBUG调试时选择模式
  2. Debug在输出窗口中选择了选项 - 在此处输入图片说明
  3. 查看断点是否在代码中击中 Debug.WriteLine
  4. Debug.AutoFlush = true在代码开头插入
  5. 尝试检查解决方案的平台是否设置为 Any CPU 而不是 x86(或 x64)。
  6. 转到 Project Properties--> Web - 在 Debugger 部分,选中 ASP.NET 选项

Reference for Point #5(Read the comment, It worked for that guy)

第 5 点的参考(阅读评论,它对那个人有用)

回答by Rohit Vats

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. If it is there delete it-->
          <clear/>
      </listeners>
    </trace>
  </system.diagnostics>

回答by Al Lelopath

For me, this solved the problem:

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

System.Diagnostics.Trace.WriteLine("whatever");

(using Traceinstead of Debug)

(使用Trace代替Debug

回答by JustAPup

For me, I needed to do this to solve the problem:

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

1. Open the project's property page
2. Under Build tab, check "Define DEBUG constant" and "Define Trace constant"

Voila!

瞧!

回答by Katsutoshi Hayashida

I had the same problem. Using Trace.WriteLine and checking "Define DEBUG constant" did not work for me.

我有同样的问题。使用 Trace.WriteLine 并检查“定义调试常量”对我不起作用。

I noticed that the output messages were found in Immediate window, instead of Output window.

我注意到输出消息是在立即窗口中找到的,而不是在输出窗口中。

Then I unchecked "Redirect all Output Window text to the Immediate Window" option in tools and solved my problem.

然后我取消选中工具中的“将所有输出窗口文本重定向到立即窗口”选项并解决了我的问题。

回答by Lucio Flavio

Using "System.Diagnostics.Debug.WriteLine" I've output in the Immediate Window :-O

使用“System.Diagnostics.Debug.WriteLine”我在即时窗口中输出:-O