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

发布于 2024-11-26 19:51:35 字数 473 浏览 0 评论 0原文

完整程序:

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”吗?

Full Program:

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

After I ran it, I had a file a.txt in my debug folder but the size is 0 bytes (and when i open it is empty of course)

Shouldn't the output had "asd" in it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何以畏孤独 2024-12-03 19:51:35

添加一个或多个

 System.Diagnostics.Debug.Flush()

语句,和/或

 System.Diagnostics.Debug.Close()

关闭该应用程序时的语句。

Add one or more

 System.Diagnostics.Debug.Flush()

statements, and/or a

 System.Diagnostics.Debug.Close()

when closing that App.

远山浅 2024-12-03 19:51:35

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

I have found this issue also a long time ago. You can get around flushing every time if you are willing to use a CriticalFinalizer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文