0

I' ve several places in my C# code, that output things to the Console. Some using Console.Writeline, some via TraceListeners like System.Diagnostics.ConsoleTraceListener.

Now I want to display all that output in a WPF textbox. Is it possible to bind the console output 1:1 in some way to a TextBox?

Or do I have to change every single call of TraceListeners or Console.Writeline to add the output to textbox.text additionally?

Konrad
  • 4,329
  • 10
  • 54
  • 88
  • 1
    Possible duplicate of [Is it possible to intercept Console output?](https://stackoverflow.com/questions/6024172/is-it-possible-to-intercept-console-output) – ASh Aug 14 '17 at 16:51

1 Answers1

2

You can use Console.OpenStandardOutput to intercept Console.Writeline()- This answer and this link explain how to implement a TextBoxStreamWriter and inject it in standard output stream.

As for ConsoleTraceListener - you should be able to write your own textbox based TraceListener and assign it to appropriate TraceSources (as they support multiple trace listeners). This answer highlights how to implement the same.

More details regarding trace sources and listeners can be found here.

Sharada Gururaj
  • 13,471
  • 1
  • 22
  • 50