SEB-Patcher/SEBPatcherUtils/PatchLogger.cs

56 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.IO;
namespace SEBPatcherUtils
{
public class PatchLogger
{
private readonly string _logFilePath;
private readonly string _logModule;
2024-10-16 08:11:06 +02:00
public PatchLogger(string logModule)
{
2024-10-16 08:11:06 +02:00
_logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SafeExamBrowser", "SEBPatcher.log");
_logModule = logModule;
}
public void Log(string message, string logLevel = "INFO")
{
string logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} [SEBPatcher] [{_logModule}] [{logLevel}] {message}";
AppendToFile(logEntry);
}
public void Info(string message)
{
Log(message, "INFO");
}
public void Error(string message)
{
Log(message, "ERROR");
}
public void Warning(string message)
{
Log(message, "WARNING");
}
public void Debug(string message)
{
Log(message, "DEBUG");
}
2024-10-16 08:11:06 +02:00
private void AppendToFile(string logEntry)
{
try
{
File.AppendAllText(_logFilePath, logEntry + Environment.NewLine);
}
catch (Exception ex)
{
Console.WriteLine($"[SEBPatcher] Failed to write to log file: {ex.Message}");
}
}
}
}