using System; namespace ZeroLevel.Logging { public sealed class DelegateLogger : ILogger { private readonly Action _handler; private readonly Action _handlerFull; public DelegateLogger(Action handler) { _handler = handler ?? throw new ArgumentNullException(nameof(handler)); } public DelegateLogger(Action handler) { _handlerFull = handler ?? throw new ArgumentNullException(nameof(handler)); } public void Dispose() { } public void Write(LogLevel level, string message) { try { if (level == LogLevel.Raw) { _handler?.Invoke(message); _handlerFull?.Invoke(level, message); } else { _handler?.Invoke($"[{DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss")} {LogLevelNameMapping.CompactName(level)}] {message}"); _handlerFull?.Invoke(level, message); } } catch { } } } }