コード例 #1
0
 private void Write(IEnumerable <LogEntry> logEntries)
 {
     lock (_lock)
     {
         if (_initIdTask != null)
         {
             _currentId  = _initIdTask.Result ?? -1;
             _initIdTask = null;
         }
         if (_preLogs != null)
         {
             logEntries = _preLogs.Select(x => x()).Concat(logEntries);
             _preLogs   = null;
         }
         var logEntriesExtra = logEntries
                               .Select(entry =>
         {
             long id        = ++_currentId;
             entry.InsertId = $"{_instanceId}:{id}";
             return(new LogEntryExtra(id, entry));
         })
                               .ToList();
         _logQ.Enqueue(logEntriesExtra);
     }
     _logUploader.TriggerUpload();
 }
コード例 #2
0
ファイル: DbLogger.cs プロジェクト: SplitView/Custom-Logger
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            var log = new LogEntity
            {
                Message  = formatter(state, exception),
                LogLevel = logLevel
            };

            _logQueue.Enqueue(log);
        }
コード例 #3
0
        private void Write(IEnumerable <LogEntry> logEntries)
        {
            DateTimeRange logEntriesLost;

            lock (_enqueueLock)
            {
                if (_initIdTask != null)
                {
                    _currentId  = _initIdTask.Result ?? -1;
                    _initIdTask = null;
                }
                var logEntriesExtra = logEntries
                                      .Select(entry =>
                {
                    long id        = ++_currentId;
                    entry.InsertId = $"{_instanceId}:{id}";
                    return(new LogEntryExtra(id, entry));
                })
                                      .ToList();
                logEntriesLost = _logQ.Enqueue(logEntriesExtra);
            }
            _logUploader.TriggerUpload(logEntriesLost);
        }