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

10
SzLib/ISzLogger.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace SzLib;
public interface ISzLogger
{
public bool LogToFile { get; set; }
public string LogFilePath { get; set; }
public void Log(string text);
public void LogError(string text);
public void LogWarning(string text);
}

View File

@@ -3,7 +3,7 @@ using SzLib.DataObjects;
namespace SzLib;
public class SzParser(ISzFileManager szFileManager)
public class SzParser(ISzFileManager szFileManager, ISzLogger szLogger)
{
private readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true };
@@ -29,7 +29,8 @@ public class SzParser(ISzFileManager szFileManager)
}
catch (Exception e)
{
throw new Exception("Could not deserialize JSON to type SzDataset: " + e.Message, e);
szLogger.LogError("Could not deserialize JSON to type SzDataset: " + e.Message);
return null;
}
}
@@ -42,7 +43,7 @@ public class SzParser(ISzFileManager szFileManager)
}
catch (Exception e)
{
Console.WriteLine("Error saving dataset: " + e.Message);
szLogger.LogError("Error saving dataset: " + e.Message);
return false;
}
}