From a Console Application project in Visual Studio, I want to redirect Console
's output to the Output Window while debugging.
To display the Output window whenever you build a project, in the Options dialog box, on the Projects and Solutions > General page, select Show Output window when build starts.
You can write run-time messages to the Output window using the Debug class or the Trace class, which are part of the System. Diagnostics class library. Use the Debug class if you only want output in the Debug version of your program. Use the Trace class if you want output in both the Debug and Release versions.
Visual Studio indicates the line on which the breakpoint is set by highlighting it and displaying a red dot in the left margin. Press ⌘ ↵ ( command + enter ) to start the program in debugging mode. Another way to start debugging is by choosing Run > Start Debugging from the menu.
Change application type to Windows before debugging. Without Console window, Console.WriteLine works like Trace.WriteLine. Don't forget to reset application back to Console type after debugging.
class DebugWriter : TextWriter { public override void WriteLine(string value) { Debug.WriteLine(value); base.WriteLine(value); } public override void Write(string value) { Debug.Write(value); base.Write(value); } public override Encoding Encoding { get { return Encoding.Unicode; } } } class Program { static void Main(string[] args) { #if DEBUG if (Debugger.IsAttached) Console.SetOut(new DebugWriter()); #endif Console.WriteLine("hi"); } }
** note that this is roughed together almost pseudo code. it works but needs work :) **
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