First, let me say that I don't know what is the exact keyword should I use to search this. I only came up with the title of this question.
I'm sure that most of the people who has been using Visual Studio are already familiar with its Output panel that prints debug information, etc. Some messages in it are outputted by the "system debugger" itself (how should I call it?), and we can write a message ourself to it by Console.Write()
, Console.WriteLine()
, Debug.Write()
, etc.
What I want to know, is there any way to capture messages that are output by the "system debugger" itself to the application that I built?
If you still can't understand what I mean, look at the illustration below:
You can see that this messages are not outputted by me manually, it's by the "system debugger":
And I want to show them in my application, say, in a TextBlock
like this:
EDIT:
As @Andy's answer suggested... I've done every step correctly. But, apparently, it can only show debug output from a manually written debugging like Debug.Write()
/WriteLine()
or Trace.Write()
/WriteLine()
. So, his answer doesn't satisfy my question.
If you create a new class that derives from TraceListener
, and then add an instance of that class to the Debug.Listeners
collection, your class should be called whenever something is written to the debug output in Visual Studio.
At a high level, I would implement it something like this:
TraceListener
, add an event. Fire this event whenever any of the Write()
methods is called, and include the text in the EventArgs
of the event.TraceListener
. Add it to the Debug.Listeners
collection, and subscribe to the event.TraceListener
's event, add the text from the EventArgs
to the TextBlock
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With