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

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

问题描述

以下 C# 程序(使用 csc hello.cs 构建)仅在控制台上打印 Hello via Console!Hello via OutputDebugString调试视图窗口.但是,我看不到任何一个 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" );
    }
}

csc 是否需要一些特殊的命令行开关?

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

我没有使用 Visual Studio 进行任何开发,这是纯命令行的东西.

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

推荐答案

正如其他人所指出的,必须注册侦听器才能读取这些流.另请注意,Debug.Write 仅在 DEBUG 构建标志被设置时才起作用,而 Trace.Write 仅在 TRACE 构建标志已设置.

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.

设置 DEBUG 和/或 TRACE 标志很容易在 Visual Studio 的项目属性中完成,或者通过向 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天全站免登陆