该错误是随机发生的,我的猜测是当交通繁忙时,但我很难复制它。每次启动业务事务时都会运行此功能。
错误:System.IO.IOException:进程无法访问文件'',因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径)
private void writeToTrafficLogFile(string data, string filePath)
{
try
{
StreamWriter logWriter;
if (!File.Exists(filePath))
{
logWriter = new StreamWriter(filePath);
}
else
{
logWriter = File.AppendText(filePath);
}
logWriter.WriteLine(DateTime.Now);
logWriter.WriteLine(data);
logWriter.WriteLine();
logWriter.Close();
}
catch (Exception error) {
sendLoggingErrorEmail(error, "Error Writing writeToTrafficLogFile", "Error Writing writeToTrafficLogFile.\r\n");
}
}
#endregion
}