Debug.Listeners: Listener can't hear anything

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
 
A

Armin Zingler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top