Reputation: 67
I have a program which will generate a log file every 10 minutes. That program will execute for around 2 months non-stop.
During testing, I found out that the files that were created only appears in the directory after the program was stopped. For example, if i start the program now and stop the execution 50 minutes later, i did not get to see the files in the directory every 10 minutes but i will see all 5 appear at once after i stopped the program.
is there a way to solve this? i would like to see the file every 10 minutes.
the file generation code:
timeDiff = now.Subtract(previous);
if (timeDiff.Minutes >= 10)
{
StreamWriter sw = File.AppendText(path + "\\file" + i +".txt");
sw.WriteLine("what ever text");
sw.Close();
i++;
}
Many thanks! and pardon for my English. (:
Upvotes: 0
Views: 163
Reputation: 136
You can check the autoflush property Quoting From MSDN
// Gets or sets a value indicating whether the StreamWriter
// will flush its buffer to the underlying stream after every
// call to StreamWriter.Write.
sw.AutoFlush = true;
Upvotes: 1