Written in Visual Studio output window

I'm trying to write a message to the output window for debugging. I searched like Java's system.out.println("")such a function. I tried Debug.Write, Console.Writeand Trace.Write. It will not be wrong, but it will not print anything.

Select "Define DEBUG constant" and "Define TRACE constant" option.

Menu ToolsOptionsDebug"will redirect all text output window to the Immediate window" option is not selected.

Configuration: Active (Debug)

Note: If relevant, I created a project, the wizard as "Windows Forms applications." I do not know where to look.


#1st Floor

use:

System.Diagnostics.Debug.WriteLine("your message here");

#2nd Floor

For me, the only Trace namespace instead of Debug work:

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

I work in C # project in Visual Studio 2010 in.


#3rd floor

Print to Visual Studio output window:

Debug.Writeline();

#4th floor

phone

System.Diagnostics.Debug.WriteLine("message");

Use .NET Core failed (V 1.0 or 1.1).

We should create and use from the Microsoft.Extensions.Loggingrecorder, but the log appears only in dotnet.exe pop-up console window, rather than in the Visual Studio "Output" window.


#5th Floor

The following work in Visual Studio 2015 for me:

OutputDebugStringW(L"Write this to Output window in VS14.");

In this reading OutputDebugStringW documents.

The input image descriptionNote that this method only works when you are debugging code ( debug mode)


#6th floor

这不是原始问题的答案。 但是,当我在寻找交互式转储对象数据的方法时发现了这个问题,我认为其他人可能会从提到这个非常有用的替代方案中受益。

我最终使用了命令窗口并输入了Debug.Print命令,如下所示。 这打印了一个可以作为文本复制的格式的内存对象,这是我真正需要的。

> Debug.Print <item>

  id: 1
  idt: null
  igad: 99
  igbd: 99
  gl_desc: "New #20"
  te_num: "1-001-001-020"

#7楼

这需要一个第三方框架,即Serilog ,但我发现这是一个非常流畅的体验,可以将输出输出到我能看到的地方。

您首先需要安装Serilog的Trace接收器 。 安装后,您需要像这样设置记录器:

Logger = new LoggerConfiguration()
    .MinimumLevel.Verbose()
    .WriteTo.Trace()
    .CreateLogger();

(您可以设置不同的最低级别或将其设置为配置值或任何正常的Serilog功能。您还可以将Trace记录器设置为特定级别以覆盖配置,或者您想要执行此操作。)

然后,您只需正常记录消息,它们就会显示在“输出”窗口中:

Logger.Information("Did stuff!");

这似乎不是什么大问题,所以让我解释一些额外的优点。 对我来说最大的一点是我可以同时登录输出窗口和控制台

Logger = new LoggerConfiguration()
    .MinimumLevel.Verbose()
    .WriteTo.Trace()
    .WriteTo.Console(standardErrorFromLevel: LogEventLevel.Error)
    .CreateLogger();

这使我在如何消耗输出方面具有很大的灵活性,而无需使用Debug.Write复制我对Console.Write所有调用。 在编写代码时,我可以在Visual Studio中运行我的命令行工具,而不必担心退出时会丢失输出。 当我部署它并需要调试某些东西(并且没有Visual Studio可用)时,控制台输出随时可用于我的消费。 当它作为计划任务运行时,也可以将相同的消息记录到文件(或任何其他类型的接收器)。

最重要的是,使用Serilog这样做可以很容易地将消息转储到多个目的地,确保无论我如何运行它,我总能随时访问输出。

它还需要非常少的设置和代码。


#8楼

For debugging purposes, unless you have the debugger listener, it would not be System.Diagnostics.Debug.Writeline()a command to release compiled code. It is written that contains all the trace listeners VS output window when running in debug mode.

For the console application. Console.Writeline()You can work but output will still be generated in the release version of the binary file.

When debugging test, debug output should appear in the normal output window; and, console.writeline output does not (and can be found in the test output window.)


House # 9

Debug.WriteLine

What you are looking for.

If not, try to do so:

Menu ToolsOptionsdebugging → uncheck the output sent immediately .


#10th floor

Add System.Diagnosticsnamespace, then you can use Debug.WriteLine()to quickly print messages to the IDE output window. For more information, please see the following:


House # 11

You may be looking for

MessageBox.Show()

Or

Debug.Writeline()

House # 12

This will write debug output window:

using System.Diagnostics;

Debug.WriteLine("Send to debug output.");
Original articles published 0 · won praise 0 · Views 2217

Guess you like

Origin blog.csdn.net/p15097962069/article/details/103921966