You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/Logging/Implementation/DelegateLogger.cs

43 lines
1.2 KiB

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

Powered by TurnKey Linux.