SimpleLogger icon indicating copy to clipboard operation
SimpleLogger copied to clipboard

System.IO.IOException: 'The process cannot access the file

Open chatay opened this issue 3 years ago • 1 comments

whilst using publish method in FileLoggerHandler with many threads/services, it throws the error cannot access the file as it is not locked. If you agree too, I will fork and modify the code to let it work simultaneously.

 public void Publish(LogMessage logMessage)
        {
            if (!string.IsNullOrEmpty(_directory))
            {
                var directoryInfo = new DirectoryInfo(Path.Combine(_directory));
                if (!directoryInfo.Exists)
                    directoryInfo.Create();
            }
            using (var writer = new StreamWriter(File.Open(Path.Combine(_directory, _fileName), FileMode.Append)))
                writer.WriteLine(_loggerFormatter.ApplyFormat(logMessage));


        }

chatay avatar Mar 02 '21 07:03 chatay

+1 - I am seeing the same issue. If the file is locked, then the logger shouldn't throw an exception.

Pull Request?

infiniteloopltd avatar Jun 27 '22 09:06 infiniteloopltd