예제 #1
0
        private async Task ProcessLogQueue(object state)
        {
            do
            {
                var batch = new List <LogMessageToWrite>();

                while (_logQueue.TryTake(out var item))
                {
                    batch.Add(item);
                }

                if (batch.Count != 0)
                {
                    await _logMessageWriter.WriteMessageAsync(batch, _cancel.Token);
                }

                await Task.Delay(WriteInterval, _cancel.Token);
            } while (!_cancel.IsCancellationRequested);
        }
예제 #2
0
        public void Log <TState>(
            LogLevel logLevel,
            EventId eventId,
            TState state,
            Exception exception,
            Func <TState, Exception, string> formatter)
        {
            var msg        = LogDtoConverter.Convert(logLevel, eventId, state, exception, formatter);
            var msgToWrite = new LogMessageToWrite(msg, logLevel);
            var writeTask  = _logMessageWriter.WriteMessageAsync(Enumerable.Repeat(msgToWrite, 1), CancellationToken.None);

            writeTask.Wait(CancellationToken.None);
        }