TextWriterTraceListener not working as expected when adding to System.Diagnostics.Debug.Listeners
Full Program:
Option Strict On : Option Explicit On Module Module1
Sub Mai开发者_StackOverflow社区n()
'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 ?
Add one or more
System.Diagnostics.Debug.Flush()
statements, and/or a
System.Diagnostics.Debug.Close()
when closing that App.
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.
精彩评论