M
MFRASER
I am trying to create a simple log file function that logs the timespan and
a message. Problem with my code is that I get an error that the file is
being access by another process. What am I doing wrong?
try
{
System.IO.StreamWriter MainWriter =
File.AppendText(c:\\ImportXMLTimeLog.txt");
System.TimeSpan TimeDiff = System.DateTime.Now.Subtract(aStartTime);
MainWriter.Write(logMessage + ", Minutes: " + TimeDiff.Minutes + ", Seconds:
" + TimeDiff.TotalSeconds + " , MiliSeconds: " + TimeDiff.TotalMilliseconds
+ "\r\n");
MainWriter.WriteLine("");
// Update the underlying file.
MainWriter.Flush();
MainWriter.Close();
}
catch{}
a message. Problem with my code is that I get an error that the file is
being access by another process. What am I doing wrong?
try
{
System.IO.StreamWriter MainWriter =
File.AppendText(c:\\ImportXMLTimeLog.txt");
System.TimeSpan TimeDiff = System.DateTime.Now.Subtract(aStartTime);
MainWriter.Write(logMessage + ", Minutes: " + TimeDiff.Minutes + ", Seconds:
" + TimeDiff.TotalSeconds + " , MiliSeconds: " + TimeDiff.TotalMilliseconds
+ "\r\n");
MainWriter.WriteLine("");
// Update the underlying file.
MainWriter.Flush();
MainWriter.Close();
}
catch{}