From b8bf7bdf30ff6d1b779056a61a73b013f99dd28c Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 20 May 2023 22:56:05 +0200 Subject: [PATCH] "Fixed" Issue with Filelogger, where program would crash if file could not be written --- Logging/FileLogger.cs | 9 ++++++++- Logging/LoggerBase.cs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Logging/FileLogger.cs b/Logging/FileLogger.cs index da0284e..20829d3 100644 --- a/Logging/FileLogger.cs +++ b/Logging/FileLogger.cs @@ -14,6 +14,13 @@ public class FileLogger : LoggerBase protected override void Write(LogMessage logMessage) { - File.AppendAllText(logFilePath, logMessage.ToString()); + try + { + File.AppendAllText(logFilePath, logMessage.ToString()); + } + catch (Exception e) + { + stdOut?.WriteLine(e); + } } } \ No newline at end of file diff --git a/Logging/LoggerBase.cs b/Logging/LoggerBase.cs index dd74e95..0458e16 100644 --- a/Logging/LoggerBase.cs +++ b/Logging/LoggerBase.cs @@ -5,7 +5,7 @@ namespace Logging; public abstract class LoggerBase : TextWriter { public override Encoding Encoding { get; } - private TextWriter? stdOut { get; } + protected TextWriter? stdOut { get; } public LoggerBase(TextWriter? stdOut, Encoding? encoding = null) {