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?
You can use Console.OpenStandardOutput to intercept
Console.Writeline()- This answer and this link explain how to implement aTextBoxStreamWriterand inject it in standard output stream.As for
ConsoleTraceListener- you should be able to write your own textbox basedTraceListenerand assign it to appropriateTraceSources(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.