I want to get my Console.WriteLine()
commands to appear in my "Output" window with my Debug.WriteLine()
statements. I think I figured out how to do this once, but I can't remember / find on google how to do it again. I seem to remember being able to do this in the app.config
file.
I find plenty of instructions on how to get console and debug statements to appear in the output of the Console, but not how to get them to appear in the "Output" window.
Is it possible?
Press F11 . Visual Studio calls the Console. WriteLine(String, Object, Object) method. The console window displays the formatted string.
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.
Start the project with Ctrl + F5 instead of just F5 . The console window will now stay open with the Press any key to continue . . . message after the program exits.
Basically the most simple solution looks like this.
public class ToDebugWriter : StringWriter
{
public override void WriteLine(string value)
{
Debug.WriteLine(value);
base.WriteLine(value);
}
}
And you must add this line to the initialization of the program:
Console.SetOut(new ToDebugWriter());
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