C# TextWriterTraceListener在添加到System.Diagnostics.Debug.Listeners时未按预期工作

C# TextWriterTraceListener在添加到System.Diagnostics.Debug.Listeners时未按预期工作,c#,.net,vb.net,debugging,system.diagnostics,C#,.net,Vb.net,Debugging,System.diagnostics,完整程序: Option Strict On : Option Explicit On Module Module1 Sub Main() 'System.Diagnostics.Debug.Listeners.Add(New System.Diagnostics.TextWriterTraceListener("C:\a.txt")) System.Diagnostics.Debug.Listeners.Add(New System.Diagnosti

完整程序:

Option Strict On : Option Explicit On Module Module1

    Sub Main()
        'System.Diagnostics.Debug.Listeners.Add(New System.Diagnostics.TextWriterTraceListener("C:\a.txt"))
        System.Diagnostics.Debug.Listeners.Add(New System.Diagnostics.TextWriterTraceListener("a.txt"))
        System.Diagnostics.Debug.WriteLine("asd")
    End Sub

End Module
运行之后,我在调试文件夹中有一个文件a.txt,但大小为0字节(打开时当然是空的)

输出中不应该有“asd”吗?

添加一个或多个

 System.Diagnostics.Debug.Flush()
声明,和/或

 System.Diagnostics.Debug.Close()

当关闭该应用程序时

我很久以前也发现了这个问题。如果您愿意使用CriticalFinalizer,每次都可以刷新。

是,.AutoFlush=True(从内存中)