为什么 TextWriterTraceListener 不能在发布模式下工作?
Why TextWriterTraceListener can't work in release mode?
该程序可以在调试模式下运行,但不能在发布模式下运行:
static void Main(string[] args)
{
Trace.Listeners.Add(new TextWriterTraceListener(@"c:\prog\a.txt"));
Debug.AutoFlush = true;
Debug.WriteLine("abc");
Debug.Close();
}
当这个程序运行处于发布模式时,它可以正常运行,但不能在a.txt中写入第"abc"行
你能告诉我为什么吗?谢谢
因为您正在使用
Debug.WriteLine("abc")
在发布模式下构建时不会编译,请改用:
Trace.WriteLine("abc")
另请注意,Trace
将在两种构建模式下执行。
该程序可以在调试模式下运行,但不能在发布模式下运行:
static void Main(string[] args)
{
Trace.Listeners.Add(new TextWriterTraceListener(@"c:\prog\a.txt"));
Debug.AutoFlush = true;
Debug.WriteLine("abc");
Debug.Close();
}
当这个程序运行处于发布模式时,它可以正常运行,但不能在a.txt中写入第"abc"行 你能告诉我为什么吗?谢谢
因为您正在使用
Debug.WriteLine("abc")
在发布模式下构建时不会编译,请改用:
Trace.WriteLine("abc")
另请注意,Trace
将在两种构建模式下执行。