fix: file logger having async issues

This commit is contained in:
2026-04-13 17:23:22 +03:00
parent e9d4c3eb64
commit 7e7b910dd3

View File

@@ -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<string> 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)