Add logging system

This commit is contained in:
Stone_Red
2026-06-10 00:28:28 +02:00
parent 1cd322a0aa
commit 91e8cbb00a
9 changed files with 214 additions and 17 deletions
+39
View File
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Concurrent;
namespace RemSox.Logging
{
public class InMemoryLogger : ILogger
{
readonly ConcurrentBag<LogEntry> logs = [];
public void Log(string message, LogSeverity severity)
{
logs.Add(new LogEntry(message, severity, DateTimeOffset.UtcNow));
}
public void LogError(string message)
{
Log(message, LogSeverity.Error);
}
public void LogInfo(string message)
{
Log(message, LogSeverity.Info);
}
public void LogWarning(string message)
{
Log(message, LogSeverity.Warning);
}
public IEnumerable<LogEntry> GetLogs(int? count = null)
{
IEnumerable<LogEntry> orderedLogs = logs.OrderBy(l => l.Timestamp);
return count.HasValue ? orderedLogs.TakeLast(count.Value) : orderedLogs;
}
}
}