2026-04-18 06:04:39 +01:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace GameCult.Logging
|
|
|
|
|
{
|
2026-04-18 13:01:24 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Appends timestamped log entries to a file on disk.
|
|
|
|
|
/// </summary>
|
2026-04-18 06:04:39 +01:00
|
|
|
public class FileLogger : ILogger
|
|
|
|
|
{
|
|
|
|
|
private readonly string _logPath;
|
|
|
|
|
|
2026-04-18 13:01:24 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new file-backed logger.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logPath">The path to the log file to append to.</param>
|
2026-04-18 06:04:39 +01:00
|
|
|
public FileLogger(string logPath = "server.log")
|
|
|
|
|
{
|
|
|
|
|
_logPath = logPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Append(string level, string message)
|
|
|
|
|
{
|
|
|
|
|
File.AppendAllText(_logPath, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{level}] {message}\n");
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-18 13:01:24 +01:00
|
|
|
/// <inheritdoc />
|
2026-04-18 06:04:39 +01:00
|
|
|
public void LogInfo(string message) => Append("INFO", message);
|
2026-04-18 13:01:24 +01:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2026-04-18 06:04:39 +01:00
|
|
|
public void LogWarning(string message) => Append("WARN", message);
|
2026-04-18 13:01:24 +01:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2026-04-18 06:04:39 +01:00
|
|
|
public void LogError(string message) => Append("ERROR", message);
|
2026-04-18 13:01:24 +01:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2026-04-18 06:04:39 +01:00
|
|
|
public void LogDebug(string message) => Append("DEBUG", message);
|
|
|
|
|
}
|
2026-04-18 13:01:24 +01:00
|
|
|
}
|