예제 #1
0
 public void Enqueue(LogMessageContext message)
 {
     if (_channel.Writer.TryWrite(message))
     {
         _messages++;
     }
 }
예제 #2
0
        private void Log <TState>(string logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            var message = $"[{DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ")}][{logLevel.PadRight(12)}] - {formatter(state, exception)} ({_category})";

            if (exception != null)
            {
                message = message + Environment.NewLine + exception.ToString();
            }
            var context = new LogMessageContext(message);

            _options.OnCreatingLogMessage(_services, context);
            _channel.Enqueue(context);
        }