Cleaning up SzCli logger implementation a bit
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user