Created
December 4, 2018 20:56
-
-
Save zeqk/221330cd42feaef83bf7d5f833a51858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Extensions.Logging; | |
public class TimedLogger<T>: ILogger<T> | |
{ | |
private readonly ILogger _logger; | |
public TimedLogger(ILogger logger) => _logger = logger; | |
public TimedLogger(ILoggerFactory loggerFactory): this(new Logger<T>(loggerFactory)) { } | |
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) => | |
_logger.Log(logLevel, eventId, state, exception, (s, ex) => $"[{DateTime.UtcNow:HH:mm:ss.fff}]: {formatter(s, ex)}"); | |
public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel); | |
public IDisposable BeginScope<TState>(TState state) => _logger.BeginScope(state); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment