From 7e7b910dd38e9610601eb286d08ff536b71f64f1 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 13 Apr 2026 17:23:22 +0300 Subject: [PATCH] fix: file logger having async issues --- Engine.Core/Debug/FileLogger.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Engine.Core/Debug/FileLogger.cs b/Engine.Core/Debug/FileLogger.cs index 060ea6a..b14a3d9 100644 --- a/Engine.Core/Debug/FileLogger.cs +++ b/Engine.Core/Debug/FileLogger.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; namespace Engine.Core.Debug; @@ -7,9 +9,21 @@ public class FileLogger : LoggerBase { public readonly string FilePath; - protected override void Write(string message) + private readonly Queue lineQueue = new(); + private Task? currentWriteTask = null; + + protected async override void Write(string message) { - File.AppendAllTextAsync(FilePath, $"{message}{Environment.NewLine}"); + lineQueue.Enqueue(message); + currentWriteTask ??= WriteLogs(); + } + + private async Task WriteLogs() + { + while (lineQueue.TryDequeue(out string? line)) + await File.AppendAllTextAsync(FilePath, $"{line}{Environment.NewLine}"); + + currentWriteTask = null; } public FileLogger(string filePath)