2024-10-15 16:42:45 +02:00
|
|
|
|
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-15 16:42:45 +02:00
|
|
|
|
{
|
2024-10-16 08:11:06 +02:00
|
|
|
|
_logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SafeExamBrowser", "SEBPatcher.log");
|
2024-10-15 16:42:45 +02:00
|
|
|
|
_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)
|
2024-10-15 16:42:45 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.AppendAllText(_logFilePath, logEntry + Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"[SEBPatcher] Failed to write to log file: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|