Exemple #1
0
 public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
 {
     if (ThreadExtensions.IsImpersonating())
     {
         _context.Push(() => {
             _logger.Log(logLevel, eventId, state, exception, formatter);
         });
     }
     else
     {
         _context.Flush();
         _logger.Log(logLevel, eventId, state, exception, formatter);
     }
 }
Exemple #2
0
        public DeferringLoggerProvider(ILoggerProvider loggerProvider)
        {
            _loggerProvider = loggerProvider;

            var token = _flusherControl.Token;

            _flusher = Task.Run(async() => {
                while (!token.IsCancellationRequested)
                {
                    _context.Flush();
                    await Task.Delay(TimeSpan.FromSeconds(5), token);
                }
            });
        }