Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm working on implementing a similar feature to capture output sent to the Console and save it to a log while still passing the output in real time to the normal Console so it doesn't break the application (eg. if it's a console application!).</p> <p>If you're still trying to do this in your own code by saving the console output (as opposed to using a logging system to save just the information you really care about), I think you can avoid the flush after each write, as long as you also override Flush() and make sure it flushes the original <code>stdoutWriter</code> you saved as well as your <code>fileWriter</code>. You want to do this in case the application is trying to flush a partial line to the console for immediate display (such as an input prompt, a progress indicator, etc), to override the normal line-buffering.</p> <p>If that approach has problems with your console output being buffered too long, you might need to make sure that WriteLine() flushes <code>stdoutWriter</code> (but probably doesn't need to flush <code>fileWriter</code> except when your Flush() override is called). But I would think that the original <code>Console.Out</code> (actually going to the console) would automatically flush its buffer upon a newline, so you shouldn't have to force it.</p> <p>You might also want to override Close() to (flush and) close your <code>fileWriter</code> (and probably <code>stdoutWriter</code> as well), but I'm not sure if that's really needed or if a Close() in the base TextWriter would issue a Flush() (which you would already override) and you might rely on application exit to close your file. You should probably test that it gets flushed on exit, to be sure. And be aware that an abnormal exit (crash) likely won't flush buffered output. If that's an issue, flushing <code>fileWriter</code> on newline may be desirable, but that's another tricky can of worms to work out.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload