简体   繁体   English

notepad ++中的System.Diagnostics.Trace类

[英]System.Diagnostics.Trace class in notepad++

I tried doing this 我试过这样做

using System;
using System.Diagnostics;
using System.IO;

public class Sample
{
    public static void Main()
    {
        Stream traceText = File.Create("trace.txt");
        TextWriterTraceListener textListener = new TextWriterTraceListener(traceText);
        Trace.Listeners.Add(textListener);

        Trace.Write("wth is goin on? I should be appearin in a txt file :(");

        Trace.Flush(); 
    }
}

and compiled with cmd, but the program just creates an empty trace.txt file.. why? 并使用cmd编译,但程序只是创建一个空的trace.txt文件..为什么?

btw I'm using the latest .NET Framework version and I'm using notepad++ not VS 顺便说一下,我使用的是最新的.NET Framework版本,我使用的是notepad ++而不是VS.

Most Trace class methods (such as Write ) are marked with [Conditional("TRACE")] attribute, which means calls to them are stripped off by compiler unless corresponding constant is defined. 大多数Trace类方法(如Write )都标有[Conditional("TRACE")]属性,这意味着除非定义了相应的常量,否则编译器会调用对它们的调用。

This constant is usually set by default when you create project in visual studio, but since you compile yourself from command line - you need to define it yourself. 在visual studio中创建项目时,默认情况下通常会设置此常量,但由于您是从命令行编译自己的 - 您需要自己定义它。

For that, either put 为此,要么放

#define TRACE

as the very first line in your code file, or pass /d:TRACE option to compiler when you compile from command line. 作为代码文件中的第一行,或者从命令行编译时将/d:TRACE选项传递给编译器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM