public void EnqueueEntry(WebLogEntry entry)
        {
            if (!_messageQueue.IsAddingCompleted)
            {
                try
                {
                    _messageQueue.Add(entry);
                    return;
                }
                catch (InvalidOperationException e)
                {
                    WriteInternalException(e);
                }
            }

            _ = WriteMessage(entry);
        }
        private async Task WriteMessage(WebLogEntry entry)
        {
            try
            {
                if (_writer == null)
                {
                    throw new Exception("Unable to write web log without connection!");
                }

                var dto = PrepareDto(entry);
                await _writer.Write(dto);
            }
            catch (Exception e)
            {
                WriteInternalException(e);
                Thread.Sleep(_exceptionSleepDuration);
            }
        }
        private LogEntry PrepareDto(WebLogEntry entry)
        {
            var dto = new LogEntry(entry.Date)
            {
                Level     = (int)entry.Level,
                Category  = entry.Category,
                EventId   = entry.EventId.Id,
                EventName = entry.EventId.Name,
                Message   = entry.Message,
                Exception = entry.Exception?.ToString()
            };

            if (entry.Scopes != null)
            {
                dto.Scopes = string.Join(" => ", entry.Scopes);
            }

            return(dto);
        }
Beispiel #4
0
        private void WriteMessage(LogLevel logLevel, EventId eventId, string message, Exception exception)
        {
            WebLogEntry entry = new WebLogEntry
            {
                Level     = logLevel,
                Date      = DateTime.UtcNow,
                Category  = _category,
                EventId   = eventId,
                Exception = exception,
                Message   = message
            };

            if (_scopeProvider != null)
            {
                entry.Scopes = new List <object>();
                _scopeProvider.ForEachScope(
                    (s, scopes) => scopes.Add(s),
                    entry.Scopes
                    );
            }

            _loggerProcessor.EnqueueEntry(entry);
        }