34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using SzCore;
|
|
|
|
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 int LogFileMaxLines { get; set; } = 100;
|
|
|
|
public void Log(string text)
|
|
{
|
|
Console.WriteLine($"{DateTime.UtcNow} : [SZ LOG] {text}");
|
|
if (LogToFile) AppendLogFile($"{DateTime.UtcNow} : [SZ LOG] {text}");
|
|
}
|
|
|
|
public void LogError(string text)
|
|
{
|
|
Console.WriteLine($"{DateTime.UtcNow} : [SZ ERR] {text}");
|
|
if (LogToFile) AppendLogFile($"{DateTime.UtcNow} : [SZ ERR] {text}");
|
|
}
|
|
|
|
public void LogWarning(string text)
|
|
{
|
|
Console.WriteLine($"{DateTime.UtcNow} : [SZ WARN] {text}");
|
|
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");
|
|
}
|
|
} |