在VB.NET win表单项目中将输出发送到stdout(控制台)

时间:2021-10-16 00:05:13

I have an application with a String variable that repeated gets a Date from a database, does something with that field, then goes onto the next row.

我有一个带有String变量的应用程序,该变量重复从数据库获取一个Date,对该字段执行某些操作,然后进入下一行。

Is there a way I can send send out some debugging information to the stdout console so I can debug better/view the progress of the program?

有没有办法可以发送一些调试信息到stdout控制台,这样我可以更好地调试/查看程序的进度?

4 个解决方案

#1


You can use Debug.WriteLine.

您可以使用Debug.WriteLine。

You can configure your application to use the ConsoleTraceListener:

您可以将应用程序配置为使用ConsoleTraceListener:

To direct all trace and debug messages to the console while the application executes, add a ConsoleTraceListener object to the application configuration file. Edit the configuration file that corresponds to the name of your application, or the app.config file in a Visual Studio 2005 project. In this file, insert an element for a ConsoleTraceListener.

要在应用程序执行时将所有跟踪和调试消息定向到控制台,请将ConsoleTraceListener对象添加到应用程序配置文件中。编辑与应用程序名称对应的配置文件,或Visual Studio 2005项目中的app.config文件。在此文件中,插入ConsoleTraceListener的元素。

The following example adds a ConsoleTraceListener object named configConsoleListener to the Listeners collection.

以下示例将名为configConsoleListener的ConsoleTraceListener对象添加到Listeners集合中。

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="configConsoleListener" 
          type="System.Diagnostics.ConsoleTraceListener" />
      </listeners>
    </trace>
  </system.diagnostics>
 </configuration>

Then you can call Debug.WriteLine and it will log to the output console.

然后你可以调用Debug.WriteLine,它将登录到输出控制台。

#2


System.Console.WriteLine will also do the trick.

System.Console.WriteLine也可以解决这个问题。

Documentation

#3


A better option is to send it to the Debugger output window. This will be visible while debugging the program and compiled out in a Release build.

更好的选择是将其发送到调试器输出窗口。这在调试程序时可见,并在Release版本中编译。

Debug.WriteLine("some message")

Calls to Console.WriteLine will fail for a WinForms project. Off the top of my head I can't remember if it will throw or fail silently, but it certainly won't work.

对于WinForms项目,调用Console.WriteLine将失败。我无法记住它是否会无声地抛出或失败,但它肯定无法正常工作。

#1


You can use Debug.WriteLine.

您可以使用Debug.WriteLine。

You can configure your application to use the ConsoleTraceListener:

您可以将应用程序配置为使用ConsoleTraceListener:

To direct all trace and debug messages to the console while the application executes, add a ConsoleTraceListener object to the application configuration file. Edit the configuration file that corresponds to the name of your application, or the app.config file in a Visual Studio 2005 project. In this file, insert an element for a ConsoleTraceListener.

要在应用程序执行时将所有跟踪和调试消息定向到控制台,请将ConsoleTraceListener对象添加到应用程序配置文件中。编辑与应用程序名称对应的配置文件,或Visual Studio 2005项目中的app.config文件。在此文件中,插入ConsoleTraceListener的元素。

The following example adds a ConsoleTraceListener object named configConsoleListener to the Listeners collection.

以下示例将名为configConsoleListener的ConsoleTraceListener对象添加到Listeners集合中。

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="configConsoleListener" 
          type="System.Diagnostics.ConsoleTraceListener" />
      </listeners>
    </trace>
  </system.diagnostics>
 </configuration>

Then you can call Debug.WriteLine and it will log to the output console.

然后你可以调用Debug.WriteLine,它将登录到输出控制台。

#2


System.Console.WriteLine will also do the trick.

System.Console.WriteLine也可以解决这个问题。

Documentation

#3


A better option is to send it to the Debugger output window. This will be visible while debugging the program and compiled out in a Release build.

更好的选择是将其发送到调试器输出窗口。这在调试程序时可见,并在Release版本中编译。

Debug.WriteLine("some message")

Calls to Console.WriteLine will fail for a WinForms project. Off the top of my head I can't remember if it will throw or fail silently, but it certainly won't work.

对于WinForms项目,调用Console.WriteLine将失败。我无法记住它是否会无声地抛出或失败,但它肯定无法正常工作。

#4