这应该是一个非常容易解决的问题,但由于某种原因,我遗漏了一些东西。我要做的就是获取我必须编写标题的字符串生成器函数,但由于某种原因它目前不是。
当我尝试将 if 语句更改为 !File.Exists(tempFileName) 时,它不会通过我的循环运行。
有什么建议么?另外,如果您需要更多信息,请告诉我。提前致谢。
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();
}