Created
August 16, 2018 13:03
-
-
Save Powerz/a51744332b2cd915d3ad60354b6bf8e8 to your computer and use it in GitHub Desktop.
ILogger<T> for old ASP.NET (not Core)
This file contains 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
// Bind ILoggerFactory to LoggerFactory | |
// Bind typeof(ILogger<>) to typeof(LoggingAdapter<>) | |
public class LoggingAdapter<T> : ILogger<T> | |
{ | |
private readonly Microsoft.Extensions.Logging.ILogger _logger; | |
public LoggingAdapter(ILoggerFactory factory) | |
{ | |
_logger = factory.CreateLogger<T>(); | |
} | |
public IDisposable BeginScope<TState>(TState state) | |
{ | |
return _logger.BeginScope(state); | |
} | |
public bool IsEnabled(LogLevel logLevel) | |
{ | |
return _logger.IsEnabled(logLevel); | |
} | |
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) | |
{ | |
_logger.Log(logLevel, eventId, state, exception, formatter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment