title: C# - Writing a header to a log file using string builder
body: <p>This should be an extremely easy fix, but for some reason I am missing something. All I am trying to do is get the String Builder function that I have to write the header, but for some reason it isnt currently. </p>
  
  <p>When I try to change the if statement to !File.Exists(tempFileName), it does not run through my loop. </p>
  
  <p>Any suggestions? Also, let me know if you need more info. Thanks in advance.</p>
  
  <pre><code>public static void Open(string tempFileName, string division,
                               int zipFiles, int conversions, int returnedFiles, int totalEmails)
      {
          StreamWriter dailyStats;
  
          //This is where I am missing something
          //I am passing in the original filename of a log, then adding "-Stats.log"
          //so I can tell the difference between what is the new stats file, and the original log file
          if (File.Exists(tempFileName))
          {
              dailyStats = new StreamWriter(tempFileName + "-Stats.log");
  
              StringBuilder sb = new StringBuilder();
              sb.Append("Division");
              sb.Append("\t");
              sb.Append("Zip Files");
              sb.Append("\t");
              sb.Append("Conversions");
              sb.Append("\t");
              sb.Append("Returned Files");
              sb.Append("\t");
              sb.Append("Total E-Mails");
              sb.Append("\t");
  
          }
          else
          {
              dailyStats = File.AppendText(tempFileName + "-Stats.log");
          }
  
          if (writeLog)
          {
              //Use a string builder to assemble the content for performance reasons
              StringBuilder s = new StringBuilder();
              s.Append(division);
              s.Append("\t");
              s.Append(zipFiles);
              s.Append("\t");
              s.Append(conversions);
              s.Append("\t");
              s.Append(returnedFiles);
              s.Append("\t");
              s.Append(totalEmails);
              s.Append("\t");
  
              dailyStats.WriteLine(s.ToString());
          }
  
          dailyStats.Close();
      }
  </code></pre>