mirror of https://github.com/ogoun/Zero.git
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.
35 lines
860 B
35 lines
860 B
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
|
|
{ }
|
|
}
|
|
}
|
|
} |