Cleaning up SzCli logger implementation a bit

This commit is contained in:
2026-01-23 23:45:54 -06:00
parent 7f232254b1
commit 74ee8eefc3
2 changed files with 11 additions and 3 deletions

View File

@@ -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");
}
}

View File

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