SimpleLogger
SimpleLogger copied to clipboard
System.IO.IOException: 'The process cannot access the file
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));
}
+1 - I am seeing the same issue. If the file is locked, then the logger shouldn't throw an exception.
Pull Request?