From 74ee8eefc3f53395829aefc611c38ec4516b715e Mon Sep 17 00:00:00 2001 From: chrisbell Date: Fri, 23 Jan 2026 23:45:54 -0600 Subject: [PATCH] Cleaning up SzCli logger implementation a bit --- SzCli/Logger.cs | 13 ++++++++++--- SzCore/ISzLogger.cs | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/SzCli/Logger.cs b/SzCli/Logger.cs index c4de83b..5a483e9 100644 --- a/SzCli/Logger.cs +++ b/SzCli/Logger.cs @@ -6,22 +6,29 @@ public class Logger(ISzFileManager fileManager) : ISzLogger { public bool LogToFile { get; set; } = true; public string LogFilePath { get; set; } = Path.Combine(fileManager.DataPath, "log.txt"); + public int LogFileMaxLines { get; set; } = 100; public void Log(string text) { Console.WriteLine($"{DateTime.UtcNow} : [SZ LOG] {text}"); - if (LogToFile) File.AppendAllText(LogFilePath, $"{DateTime.UtcNow} : [SZ LOG] {text}\n"); + if (LogToFile) AppendLogFile($"{DateTime.UtcNow} : [SZ LOG] {text}"); } public void LogError(string text) { Console.WriteLine($"{DateTime.UtcNow} : [SZ ERR] {text}"); - if (LogToFile) File.AppendAllText(LogFilePath, $"{DateTime.UtcNow} : [SZ ERR] {text}\n"); + if (LogToFile) AppendLogFile($"{DateTime.UtcNow} : [SZ ERR] {text}"); } public void LogWarning(string text) { Console.WriteLine($"{DateTime.UtcNow} : [SZ WARN] {text}"); - if (LogToFile) File.AppendAllText(LogFilePath, $"{DateTime.UtcNow} : [SZ WARN] {text}\n"); + if (LogToFile) AppendLogFile($"{DateTime.UtcNow} : [SZ WARN] {text}"); + } + + private void AppendLogFile(string text) + { + // TODO: Make sure log file adheres to LogFileMaxLines + File.AppendAllText(LogFilePath, text + "\n"); } } \ No newline at end of file diff --git a/SzCore/ISzLogger.cs b/SzCore/ISzLogger.cs index c1d5c21..59c4ec8 100644 --- a/SzCore/ISzLogger.cs +++ b/SzCore/ISzLogger.cs @@ -4,6 +4,7 @@ public interface ISzLogger { public bool LogToFile { get; set; } public string LogFilePath { get; set; } + public int LogFileMaxLines { get; set; } public void Log(string text); public void LogError(string text); public void LogWarning(string text);