Debug.Listeners: Listener can't hear anything

  • Thread starter Thread starter Armin Zingler
  • Start date Start date
A

Armin Zingler

Hi,

I add a TraceListener to Debug.Listeners. After that I use Debug.writeline.
Problem: Nothing arrives at the listener.

Code:
Dim ts As New TraceStream
Debug.Listeners.Add(New TextWriterTraceListener(ts))


Class Tracestream is a class inherited from IO.Stream:

Public Class TraceStream
Inherits IO.Stream

Public Overrides ReadOnly Property CanRead() As Boolean
Get
Return False
End Get
End Property

Public Overrides ReadOnly Property CanWrite() As Boolean
Get
Return True
End Get
End Property

'....other overrides

Public Overrides Sub Write( _
ByVal buffer() As Byte, ByVal offset As Integer, _
ByVal count As Integer)
'...
End Sub
End Class

I expect method Write to be called whenever Debug.Writeline is called, but
this doesn't happen. CanRead and CanWrite do get called.

Do I have a problem in understanding the Listeners concept?


Armin
 
Armin Zingler said:
Hi,

I add a TraceListener to Debug.Listeners. After that I use
Debug.writeline. Problem: Nothing arrives at the listener.

Code:
Dim ts As New TraceStream
Debug.Listeners.Add(New TextWriterTraceListener(ts))


Problem solved: The Streamwriter created internally writes to a buffer
before writing to the Stream. Solution:

Dim ts As New TraceStream
Dim sw As New IO.StreamWriter(ts)

sw.AutoFlush = True
Debug.Listeners.Add(New TextWriterTraceListener(sw))



Armin
 
Back
Top