System.Diagnostics.Debug.Write输出出现在哪里? [英] Where does System.Diagnostics.Debug.Write output appear?

查看:2530
本文介绍了System.Diagnostics.Debug.Write输出出现在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下C#程序(使用 csc hello.cs 构建)在控制台上打印 Hello通过Console!和$ code> Hello通过OutputDebugString 在DebugView窗口中。但是,我看不到任何一个 System.Diagnostics。* 调用。为什么是这样?

The following C# program (built with csc hello.cs) prints just Hello via Console! on the console and Hello via OutputDebugString in the DebugView window. However, I cannot see either of the System.Diagnostics.* calls. Why is that?

using System;
using System.Runtime.InteropServices;
class Hello {
    [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
    public static extern void OutputDebugString(string message);

    static void Main() {
        Console.Write( "Hello via Console!" );
        System.Diagnostics.Debug.Write( "Hello via Debug!" );
        System.Diagnostics.Trace.Write( "Hello via Trace!" );
        OutputDebugString( "Hello via OutputDebugString" );
    }
}

是否有可能需要一些特殊的命令行开关

Is there maybe some special command-line switches required for csc?

我没有使用Visual Studio进行任何开发,这是纯粹的命令行内容。 / p>

I'm not using Visual Studio for any of my development, this is pure commandline stuff.

推荐答案

正如其他人所指出的,听众必须注册才能读取这些流。另外请注意,如果设置了 DEBUG build标志,那么 Debug.Write 只会起作用,而如果设置了 TRACE 构建标志,Trace.Write 将起作用。

As others have pointed out, listeners have to be registered in order to read these streams. Also note that Debug.Write will only function if the DEBUG build flag is set, while Trace.Write will only function if the TRACE build flag is set.

设置可以在Visual Studio的项目属性中轻松完成 DEBUG 和/或 TRACE 标志,或者将以下参数提供给csc.exe

Setting the DEBUG and/or TRACE flags is easily done in the project properties in Visual Studio or by supplying the following arguments to csc.exe


/ define:DEBUG; TRACE

这篇关于System.Diagnostics.Debug.Write输出出现在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆