title: StreamWriter not writing data
body: <p>I am using StraemWriter to log text messages to a log file. The log file should be created if it doesn't exist, appended to if the file creation date is less than a given time or recreated if created before that time. I am using the class/code below</p>
  
  <pre><code>public static class LogIt
  {
      private const string LOG_FNAME = @"Logfile.log";
  
      public static void WriteMsg(string msg)
      {
          bool append = true;
          if (File.Exists(LOG_FNAME))
          {
              //DateTime delDate = DateTime.Now.AddDays(-1);
              DateTime delDate = DateTime.Now.AddMinutes(-30);
              DateTime fileCreatedDate = File.GetCreationTime(LOG_FNAME);
              if (DateTime.Compare(fileCreatedDate, delDate) &lt; 0)
              {
                  Console.WriteLine("DELETE FILE");
                  File.Delete(LOG_FNAME);
              }
          }
  
          using (StreamWriter sw = new StreamWriter(LOG_FNAME, append))
          {
              sw.WriteLine(msg);
          }
  
          Console.WriteLine(msg);
      }
  }
  </code></pre>
  
  <p>This class is used by a simple console app run by the Task Scheduler which runs every x minutes. </p>
  
  <p>The message are written as follows:</p>
  
  <pre><code>LogIt.WriteMsg("Log this message");
  </code></pre>
  
  <p>The messages are logged file when the file is initially created however when the file creation date is past the delete date, the file is recreated but no subsequent messages are ever written to the file.</p>
  
  <p>Any ideas on why?</p>