Reputation: 571
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.
Upvotes: 3
Views: 464
Reputation: 2617
In effect you are answering the same question as this Capture debug output in C#
so you can use the answer to that question
or alternative use MS DebugView tool as explained here https://wpf.2000things.com/2017/06/29/1212-viewing-wpf-trace-output-outside-of-visual-studio/
Upvotes: 0
Reputation: 30418
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
.Upvotes: 2