SEB-Patcher/SEBPatcherUtils/PatchLogger.cs

55 lines
1.3 KiB
C#

using System;
using System.IO;
namespace SEBPatcherUtils
{
public class PatchLogger
{
private readonly string _logFilePath;
private readonly string _logModule;
public PatchLogger(string logModule, string logFilePath)
{
_logFilePath = logFilePath;
_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");
}
public 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}");
}
}
}
}