【问题标题】:Why TextWriterTraceListener can't work in release mode?为什么 TextWriterTraceListener 不能在发布模式下工作?
【发布时间】:2017-11-06 08:17:19
【问题描述】:

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

 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”行 你能教我为什么吗?谢谢

【问题讨论】:

  • 不能工作是什么意思?你有任何错误或类似的东西吗?请提供更多信息。
  • 没有错误,但是使用realse模式时prog不能在a.txt中写入“abc”
  • 您正在使用 Debug 对其进行写入,而 Debug 在发布模式下不起作用。它的目的是写你不想在发布模式下看到的东西。使用Trace.WriteLine 就可以了。
  • 谢谢...我犯了一个幼稚的错误...

标签: c# trace release-mode debug-mode


【解决方案1】:

因为你正在使用

Debug.WriteLine("abc")

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

Trace.WriteLine("abc")

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

【讨论】:

    猜你喜欢
    • 2021-12-31
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 2018-10-23
    • 2022-06-27
    • 1970-01-01
    相关资源
    最近更新 更多