StreamWriter/StreamReader File In Use By Another Process
问题 I have a StreamWriter object to write to a log file, it is initialised as follows: StreamWriter streamWriter = File.AppendText(GetLogFilePath()); streamWriter.AutoFlush = true; Later in my code, I need to close the log file, and then read in part of the logged out contents. I have the following code: streamWriter.Close(); streamWriter = null; StreamReader logFileStream = File.OpenText(GetLogFilePath()); This is throwing an exception: The process cannot access the file because it is being used