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

35 lines
836 B

using System;
namespace ZeroLevel.Logging
{
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.