I am using a streamwriter to write to a file stream like so
using(StreamWriter writer = File.AppendText('MyFile.csv'))
{
writer.WriteLine("Header1,Header2")
//Write multiple lines based on some logic
DoSomeOtherThings(writer)
writer.Flush();
}
If my application errors in the middle of writing, I do not want to write to the file at all. To do this I thought I would just not have to flush until the end. However even if there is an error any data that was writing is saved to my file.
Is there a way to disregard the buffer of the StreamWriter so It does not save the data to the file unless it reaches the end of the logic?