Skip to content
Tags

File Cleanup part 2

by on August 16, 2012

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");
}
}

From → C#, Code Snippets

Leave a Comment

Leave a comment

NE1 Atoll

The Official blog of NE1 Games

Selenium for .Net using C# language

Adventures in Coding, gaming and other fun things in my life

Coded UI 101 - Understanding Coded UI Tests

Adventures in Coding, gaming and other fun things in my life