-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathTimedLogger.cs
24 lines (18 loc) · 890 Bytes
/
TimedLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace marysue_encoder
{
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.Now:yyyy-MM-dd HH:mm:ss.fff}]: {formatter(s, ex)}");
public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);
public IDisposable BeginScope<TState>(TState state) => _logger.BeginScope(state);
}
}