Added a logger interface
This commit is contained in:
27
SzCli/Logger.cs
Normal file
27
SzCli/Logger.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user