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)