当添加到System.Diagnostics.Debug.Listeners时,TextWriterTraceListe

本文关键字:Listeners TextWriterTraceListe Debug Diagnostics 添加 System | 更新日期: 2023-09-27 18:03:53

完整程序:

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.t txt,但大小是0字节(当我打开它时当然是空的)

输出中不应该有"asd"吗?

添加一个或多个

 System.Diagnostics.Debug.Flush()

语句,和/或

 System.Diagnostics.Debug.Close()

当添加到System.Diagnostics.Debug.Listeners时,TextWriterTraceListe

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