Tag: 文件 安全性

文件共享无法按预期工作

我有一个文件共享问题,我的进程正在尝试读取日志文件,而它当前仍由NLog打开。 在诊断问题时,我发现了令人惊讶的事情。 以下失败: using (var fileStream1 = new FileStream(“test.file”, FileMode.Append, FileAccess.Write, FileShare.Read)) using (var fileStream2 = new FileStream(“test.file”, FileMode.Open, FileAccess.Read, FileShare.Read)) { } 第二个FileStream构造函数调用失败,其中: System.IO.IOException was unhandled Message=The process cannot access the file ‘c:\…\test.file’ because it is being used by another process. Source=mscorlib StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess […]