I’ve decided to add a logging mechanism to my application so I can catch any errors or exceptions that are thrown. I’ve noticed that when an entry to the log is created it is not added to the log, it seems to overwrite everything that is in the file so there is only ever one entry.
I have a feeling it’s something simple that I’m missing but I don’t really use the System.IO namespace very often.
Creating/Checking for the log file:
public static void SetWorkingDirectory(string path)
{
_workingDirectory = path + "\\ErrorLog.txt";
if(!File.Exists(_workingDirectory))
{
File.Create(_workingDirectory);
}
pathSet = true;
}
Adding to the log:
public static bool Add(string message)
{
StringBuilder str = new StringBuilder();
str.Append(System.DateTime.Now);
str.Append(" ");
str.Append(message);
str.Append(" \n");
using (StreamWriter writer = new StreamWriter(_workingDirectory))
{
writer.Write(str.ToString());
}
return true;
}
The log itself:

Try using this constructor and passing true for the second argument so it opens the file in append mode.