roadie/Roadie.Api.Library/Processors/EventMessageLogger.cs
Steven Hildreth ca5db4cb17 resolves #16
2019-07-06 22:16:33 -05:00

31 lines
No EOL
854 B
C#

using Microsoft.Extensions.Logging;
using System;
namespace Roadie.Library.Processors
{
public class EventMessageLogger<T> : ILogger<T>, IEventMessageLogger
{
public event EventHandler<EventMessage> Messages;
public IDisposable BeginScope<TState>(TState state)
{
return null;
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception,
Func<TState, Exception, string> formatter)
{
Messages?.Invoke(this, new EventMessage { Level = logLevel, Message = formatter(state, exception) });
}
private void OnEventMessage(EventMessage message)
{
Messages?.Invoke(this, message);
}
}
}