2

I'm using this approach to redirect the console output in C#. The problem is, it doesn't flush when I set a breakpoint in debug mode.

Sol 1, sol 2 and sol 3 are too complicated. I don't want to use the process class. Is there any simple way to flush the output in C#?

Or, since I'm using VS2013 for debugging, does anyone know if there is a flush button in VS2013 to flush the output?

Community
  • 1
  • 1
user3813057
  • 891
  • 3
  • 13
  • 31

1 Answers1

8

Open the Immediate Window, Debug > Windows > Immediate Window.

Type in Console.Out.Flush() and hit Enter. This will invoke Flush on the output stream, on another thread, without interfering with your current breakpoint.

Xenolightning
  • 4,140
  • 1
  • 26
  • 34
  • Coupled with the first answer here: https://stackoverflow.com/questions/9009726/where-does-console-output-go-in-an-iis-hosted-app/9009837#9009837 This will let you see line-by-line output from an IIS Web app. I'm trouble-shooting a package that works everywhere (Fwk, Core, Win, Linux...) except in IIS, where it throws an exception with no location or other information, so I'm lacing the package with Console.WriteLine(...);Console.Out.Flush();" to trace its progress and see where it's crashing. – BRebey Nov 18 '20 at 02:54