Added a logger interface
This commit is contained in:
10
SzLib/ISzLogger.cs
Normal file
10
SzLib/ISzLogger.cs
Normal 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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user