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

34 lines
845 B

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

Powered by TurnKey Linux.