diff --git a/framework/Furion.Pure/Logging/Implantations/File/FileLoggingWriter.cs b/framework/Furion.Pure/Logging/Implantations/File/FileLoggingWriter.cs index 3b85435d709..41c2cba52a7 100644 --- a/framework/Furion.Pure/Logging/Implantations/File/FileLoggingWriter.cs +++ b/framework/Furion.Pure/Logging/Implantations/File/FileLoggingWriter.cs @@ -329,12 +329,24 @@ internal async Task WriteAsync(LogMessage logMsg, bool flush) { if (_textWriter == null) return; - CheckForNewLogFile(); - await _textWriter.WriteLineAsync(logMsg.Message); + try + { + CheckForNewLogFile(); + await _textWriter.WriteLineAsync(logMsg.Message); - if (flush) + if (flush) + { + await _textWriter.FlushAsync(); + } + } + catch (Exception ex) { - await _textWriter.FlushAsync(); + // 处理文件写入错误 + if (_options.HandleWriteError != null) + { + var fileWriteError = new FileWriteError(_fileName, ex); + _options.HandleWriteError(fileWriteError); + } } } diff --git a/framework/Furion/Logging/Implantations/File/FileLoggingWriter.cs b/framework/Furion/Logging/Implantations/File/FileLoggingWriter.cs index 3b85435d709..41c2cba52a7 100644 --- a/framework/Furion/Logging/Implantations/File/FileLoggingWriter.cs +++ b/framework/Furion/Logging/Implantations/File/FileLoggingWriter.cs @@ -329,12 +329,24 @@ internal async Task WriteAsync(LogMessage logMsg, bool flush) { if (_textWriter == null) return; - CheckForNewLogFile(); - await _textWriter.WriteLineAsync(logMsg.Message); + try + { + CheckForNewLogFile(); + await _textWriter.WriteLineAsync(logMsg.Message); - if (flush) + if (flush) + { + await _textWriter.FlushAsync(); + } + } + catch (Exception ex) { - await _textWriter.FlushAsync(); + // 处理文件写入错误 + if (_options.HandleWriteError != null) + { + var fileWriteError = new FileWriteError(_fileName, ex); + _options.HandleWriteError(fileWriteError); + } } }