【问题标题】:TextWriterTraceListener not working as expected when adding to System.Diagnostics.Debug.Listeners添加到 System.Diagnostics.Debug.Listeners 时,TextWriterTraceListener 无法按预期工作
【发布时间】:2011-10-16 07:03:54
【问题描述】:

完整程序:

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

【问题讨论】:

    标签: c# .net vb.net debugging system.diagnostics


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      添加一个或多个

       System.Diagnostics.Debug.Flush()
      

      陈述,和/或

       System.Diagnostics.Debug.Close()
      

      关闭该应用程序时。

      【讨论】:

      • 是的,.AutoFlush = True(来自内存)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-23
      • 2014-12-09
      • 2016-01-13
      相关资源
      最近更新 更多