I have a quartz.net scheduled job. Everytime it runs, i need to update a text file the datetime the job last ran. This file will always have only one line ie. the date the job last ran. What is the best way to write this one line text file thread safe?
I amusing the following code:
private static object locker = new Object();
public void WriteToFile(StringBuilder text)
{
lock (locker)
{
using (FileStream file = new FileStream(Filepath, FileMode.Append, FileAccess.Write, FileShare.Read))
using (StreamWriter writer = new StreamWriter(file, Encoding.Unicode))
{
writer.Write(text.ToString());
}
}
}
Thanks