mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 09:06:23 +02:00
Reorganize project structure
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
namespace RemSox.Kernel.Logging;
|
||||
|
||||
public interface ILogger
|
||||
{
|
||||
void Log(string message, LogSeverity severity);
|
||||
|
||||
void LogInfo(string message);
|
||||
|
||||
void LogError(string message);
|
||||
|
||||
void LogWarning(string message);
|
||||
|
||||
IEnumerable<LogEntry> GetLogs(int? count = null);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace RemSox.Kernel.Logging;
|
||||
|
||||
public class InMemoryLogger : ILogger
|
||||
{
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace RemSox.Kernel.Logging;
|
||||
|
||||
public record LogEntry(string Message, LogSeverity Severity, DateTimeOffset Timestamp);
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace RemSox.Kernel.Logging;
|
||||
|
||||
public enum LogSeverity
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace RemSox.Kernel.Logging;
|
||||
|
||||
public class ProxyLogger(IEnumerable<ILogger> loggers) : ILogger
|
||||
{
|
||||
public void Log(string message, LogSeverity severity)
|
||||
{
|
||||
foreach (ILogger logger in loggers)
|
||||
{
|
||||
logger.Log(message, severity);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return loggers.SelectMany(logger => logger.GetLogs(count / loggers.Count())).OrderBy(entry => entry.Timestamp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user