public async ValueTask DisposeAsync()
        {
            if (_queue.Count == 0)
            {
                return;
            }
            await _flusher.BeginAsync(_appender.GetCancellationToken());

            while (_queue.TryDequeue(out var entry))
            {
                await _flusher.Add(entry, _appender.GetCancellationToken());
            }
            await _flusher.EndAsync(_appender.GetCancellationToken());
        }
Esempio n. 2
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            var cancellationToken = _appender.GetCancellationToken();

            var entry = new LogEntry
            {
                LogLevel  = logLevel,
                EventId   = eventId.Id,
                EventName = eventId.Name,
                State     = SerializeState(state),
                Exception = SerializeException(exception),
                Message   = formatter(state, exception)
            };

            _appender.Append(entry, cancellationToken);
        }