C# 写入 Visual Studio 的输出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9466838/
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
Writing to output window of Visual Studio
提问by previous_developer
I am trying to write a message to the output window for debugging purposes. I searched for a function like Java's system.out.println(""). I tried Debug.Write, Console.Write, and Trace.Write. It does not give an error, but it does not print anything either.
我正在尝试将消息写入输出窗口以进行调试。我搜索了一个像 Java 的system.out.println(""). 我试过Debug.Write, Console.Write, 和Trace.Write。它不会给出错误,但也不会打印任何内容。
"Define DEBUG constant" and "Define TRACE constant" options are checked.
选中“定义调试常量”和“定义跟踪常量”选项。
Menu Tools→ Options→ Debugging→ "Redirect all Output Window text to the Immediate Window"option is not checked.
菜单工具→选项→调试→ “将所有输出窗口文本重定向到立即窗口”选项未选中。
Configuration: Active (Debug)
配置:活动(调试)
Note: I created a project with the wizard as "Windows Forms Application" if relevant. I have no idea where to look.
注意:如果相关,我使用向导创建了一个项目为“Windows 窗体应用程序”。我不知道去哪里看。
采纳答案by Bhargav Bhat
Add the System.Diagnosticsnamespace, and then you can use Debug.WriteLine()to quickly print a message to the output window of the IDE. For more details, please refer to these:
添加System.Diagnostics命名空间,然后您可以使用它Debug.WriteLine()来快速将消息打印到 IDE 的输出窗口。有关更多详细信息,请参阅以下内容:
回答by Micah Armantrout
Debug.WriteLine
is what you're looking for.
就是你要找的。
If not, try doing this:
如果没有,请尝试这样做:
Menu Tools→ Options→ Debugging→ uncheck Send Output to Immediate.
菜单工具→选项→调试→ 取消选中Send Output to Immediate。
回答by dansasu11
You may be looking for
您可能正在寻找
MessageBox.Show()
or
或者
Debug.Writeline()
回答by veight
This will write to the debug output window:
这将写入调试输出窗口:
using System.Diagnostics;
Debug.WriteLine("Send to debug output.");
回答by Luqman
Use:
用:
System.Diagnostics.Debug.WriteLine("your message here");
回答by Zac
For me, only the Tracenamespace and not the Debug one worked:
对我来说,只有Trace命名空间而不是 Debug 命名空间有效:
System.Diagnostics.Trace.WriteLine("message");
I'm working in a C# project under Visual Studio 2010.
我正在 Visual Studio 2010 下的 C# 项目中工作。
回答by Amir Twito
Print to the output window of the Visual Studio:
打印到 Visual Studio 的输出窗口:
Debug.Writeline();
回答by Paul Gorbas
The call
电话
System.Diagnostics.Debug.WriteLine("message");
fails when working with .NET Core(V 1.0 or 1.1).
使用.NET Core(V 1.0 或 1.1)时失败。
We are supposed to create and use a logger from Microsoft.Extensions.Logging, but that log only appears in the dotnet.exe popup console window, not in Visual Studio's Output window.
我们应该从 中创建和使用记录器Microsoft.Extensions.Logging,但该日志仅出现在 dotnet.exe 弹出控制台窗口中,而不出现在 Visual Studio 的输出窗口中。
回答by Mona Jalal
回答by djabraham
This is not an answer to the original question. But since I found this question when searching for a means of interactively dumping object data, I figured others may benefit from mentioning this very useful alternative.
这不是原始问题的答案。但是由于我在搜索交互式转储对象数据的方法时发现了这个问题,我认为其他人可能会从提到这个非常有用的替代方法中受益。
I ultimately used the Command Window and entered the Debug.Printcommand, as shown below. This printed a memory object in a format that can be copied as text, which is all I really needed.
我最终使用了Command Window,输入了Debug.Print命令,如下图。这以一种可以复制为文本的格式打印了一个内存对象,这正是我真正需要的。
> Debug.Print <item>
id: 1
idt: null
igad: 99
igbd: 99
gl_desc: "New #20"
te_num: "1-001-001-020"


