title: How to protect log from application crash?
body: <p>I've created a simple logger which, well, logs everything of importance into a text file. I'm using <code>std::ofstream</code> but there's a problem - when the program doesn't close the file (call <code>std::ofstream::close()</code>) for whatever reason (like crash), the created log is actually empty (0 size). And since the log is most useful in exceptional situations (when something goes wrong) - you see the problem.</p>
  
  <p>Is there any way to protect my log from that? I could try closing the file after writing every couple of lines and using append - but that still doesn't protect me from the situation when the program crashes in the middle of logging/before closing the file. Is there any solution or am I just doomed?</p>