Added a logger interface

This commit is contained in:
2026-01-23 23:39:57 -06:00
parent b500b71e62
commit f78f8fdf57
4 changed files with 52 additions and 11 deletions

27
SzCli/Logger.cs Normal file
View File

@@ -0,0 +1,27 @@
using SzLib;
namespace SzCli;
public class Logger(ISzFileManager fileManager) : ISzLogger
{
public bool LogToFile { get; set; } = true;
public string LogFilePath { get; set; } = Path.Combine(fileManager.DataPath, "log.txt");
public void Log(string text)
{
Console.WriteLine($"{DateTime.UtcNow} : [SZ LOG] {text}");
if (LogToFile) File.AppendAllText(LogFilePath, $"{DateTime.UtcNow} : [SZ LOG] {text}\n");
}
public void LogError(string text)
{
Console.WriteLine($"{DateTime.UtcNow} : [SZ ERR] {text}");
if (LogToFile) File.AppendAllText(LogFilePath, $"{DateTime.UtcNow} : [SZ ERR] {text}\n");
}
public void LogWarning(string text)
{
Console.WriteLine($"{DateTime.UtcNow} : [SZ WARN] {text}");
if (LogToFile) File.AppendAllText(LogFilePath, $"{DateTime.UtcNow} : [SZ WARN] {text}\n");
}
}