File Cleanup part 2
I realised that at times, my original log file was sticking around and not being archived. This is due to me running tests and not running the archive function at the end of a test. So basically what was happening was the logging would just append to the currently existing file.
This is fine, however, I prefer to have logs that are freshly started each time I run my tests.
So here’s what I came up with:
public void deleteLogFile()
{
string fileToDelete = @"path\to\logfile\filename.html" //This will be the path and filename of your log file
if (File.Exists(fileToDelete))
{
Console.WriteLine("Deleting old log file");
File.Delete(fileToDelete);
}
else
{
Console.WriteLine("No existing log file to delete. Creating New log file");
}
}