1

该程序可以在调试模式下工作,但不能在发布模式下工作:

 static void Main(string[] args)
    {
        Trace.Listeners.Add(new TextWriterTraceListener(@"c:\prog\a.txt"));
        Debug.AutoFlush = true;
        Debug.WriteLine("abc");
        Debug.Close();
    }

当这个程序在release模式下运行时,它可以正常运行,但是不能在a.txt中写“abc”行你能教我为什么吗?谢谢

4

1 回答 1

1

因为你正在使用

Debug.WriteLine("abc")

在发布模式下构建时不会编译,请改用:

Trace.WriteLine("abc")

另请注意,将Trace在两种构建模式下执行。

于 2017-11-09T19:53:06.090 回答