From 767fc28488fbbea9d1125f91934f4b882275890c Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sat, 21 Jun 2025 00:26:42 +0300 Subject: [PATCH] refactor: file logger relative path to full path conversion --- Engine.Core/Debug/FileLogger.cs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Engine.Core/Debug/FileLogger.cs b/Engine.Core/Debug/FileLogger.cs index 9c44b11..98b4032 100644 --- a/Engine.Core/Debug/FileLogger.cs +++ b/Engine.Core/Debug/FileLogger.cs @@ -7,18 +7,23 @@ public class FileLogger : LoggerBase { public readonly string FilePath; - public FileLogger(string filePath) - { - FilePath = filePath; - - if (Path.GetDirectoryName(filePath) is string directoryPath) - Directory.CreateDirectory(directoryPath); - - File.Open(filePath, FileMode.Create).Close(); - } - protected override void Write(string message) { File.AppendAllTextAsync(FilePath, $"{message}{Environment.NewLine}"); } + + public FileLogger(string filePath) + { + FilePath = filePath; + + bool isRelativePath = Path.GetFullPath(filePath).CompareTo(filePath) != 0; + + if (isRelativePath) + FilePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath)); + + if (Path.GetDirectoryName(FilePath) is string directoryPath) + Directory.CreateDirectory(directoryPath); + + File.Open(FilePath, FileMode.Create).Close(); + } }