"Fixed" Issue with Filelogger, where program would crash if file could not be written

This commit is contained in:
glax 2023-05-20 22:56:05 +02:00
parent d6af014cb7
commit b8bf7bdf30
2 changed files with 9 additions and 2 deletions

View File

@ -13,7 +13,14 @@ public class FileLogger : LoggerBase
} }
protected override void Write(LogMessage logMessage) protected override void Write(LogMessage logMessage)
{
try
{ {
File.AppendAllText(logFilePath, logMessage.ToString()); File.AppendAllText(logFilePath, logMessage.ToString());
} }
catch (Exception e)
{
stdOut?.WriteLine(e);
}
}
} }

View File

@ -5,7 +5,7 @@ namespace Logging;
public abstract class LoggerBase : TextWriter public abstract class LoggerBase : TextWriter
{ {
public override Encoding Encoding { get; } public override Encoding Encoding { get; }
private TextWriter? stdOut { get; } protected TextWriter? stdOut { get; }
public LoggerBase(TextWriter? stdOut, Encoding? encoding = null) public LoggerBase(TextWriter? stdOut, Encoding? encoding = null)
{ {