title: Will StreamWriter.Flush() also call FileStream.Flush()?
body: <p>I have a StreamWriter which underlying stream is a <code>FileStream</code>. Will the following code guarantee that the <code>FileStream</code> also flushes its buffer into the actual file on the file system, or do I need to explicitly call <code>Flush()</code> on the <code>FileStream</code>?</p>
  
  <pre><code>using (var fs = new FileStream("blabla", FileMode.Append)) {
      using (var sw = new StreamWriter(fs)) {
          sw.WriteLine("Hello, I want to be flushed.");
          sw.Flush(); //I need this to also flush onto the file, not just to the FileStream
      }
  }
  </code></pre>
  
  <p>As per <a href="http://msdn.microsoft.com/en-us/library/system.io.streamwriter.flush.aspx" rel="noreferrer">MSDN</a>, "<em>Flushing the stream will not flush its underlying encoder unless you explicitly call Flush or Close</em>", but I do not know if a FileStream can be considered an "underlying encoder".</p>
  
  <p>Also, if I don't specify FileOptions.WriteThrough, am I guaranteed that the OS will eventually write the flushed line onto the disk even if the program crashes before the two streams have been closed (assuming for example no <code>using {}</code> blocks, only a call to <code>Flush()</code>)?</p>
  
  <p>In my scenario I need to leave the stream open (for logging) so I cannot use <code>using {}</code> blocks, but I would like to make sure data will always be written to the disk even if the program crashes. I can afford to lose data if there is a power shutdown and the OS has not flushed onto the disk, but otherwise I need the OS to eventually flush even if I never properly call <code>Close()</code> on the stream. </p>