コード例 #1
0
        protected override async Task EmitBatchAsync(IEnumerable <LogEvent> events)
        {
            if (_switcher.CurrentMode == Mode.Fallback)
            {
                foreach (var logEvent in events)
                {
                    _fallbackSink.Emit(logEvent);
                }

                return;
            }

            try
            {
                await _kafkaSink.LogEntriesAsync(events);
            }
            catch (Exception ex)
            {
                _switcher.SwitchToFallback(ex);

                foreach (var logEvent in events)
                {
                    _fallbackSink.Emit(logEvent);
                }
            }
        }
コード例 #2
0
 public void Emit(LogEvent logEvent)
 {
     if (_condition(logEvent))
     {
         _wrapped.Emit(logEvent);
     }
 }
コード例 #3
0
 public void Emit(LogEvent logEvent)
 {
     if (logEvent.Level >= filteredLevel || Keyboard.PrimaryDevice.IsKeyToggled(Key.Scroll))
     {
         innerSink.Emit(logEvent);
     }
 }
コード例 #4
0
        public void Emit(LogEvent logEvent)
        {
            var timestamp = _getTimestamp(logEvent);
            var surrogate = new LogEvent(timestamp, logEvent.Level, logEvent.Exception, logEvent.MessageTemplate,
                                         logEvent.Properties.Select(kv => new LogEventProperty(kv.Key, kv.Value)));

            _target.Emit(surrogate);
        }
コード例 #5
0
ファイル: Log.cs プロジェクト: Seti-0/NSprak
        public void AddSink(ILogEventSink sink)
        {
            foreach (LogEvent previousEvent in _events)
            {
                sink.Emit(previousEvent);
            }

            _sinks.Enqueue(sink);
        }
コード例 #6
0
        private void WriteEventsToSinks()
        {
            var copyOfEvents = _eventEntries.ToArray();

            foreach (var entry in copyOfEvents.Where(e => e.WriteToSink))
            {
                _sink.Emit(entry.Event);
            }
        }
コード例 #7
0
ファイル: CopyingSink.cs プロジェクト: nickvane/serilog
        public void Emit(LogEvent logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException("logEvent");
            }
            var copy = new LogEvent(logEvent.Timestamp, logEvent.Level, logEvent.Exception, logEvent.MessageTemplate, logEvent.Properties.Values);

            _copyToSink.Emit(copy);
        }
コード例 #8
0
        public void Emit(LogEvent logEvent)
        {
            foreach (var logEventFilter in _filters)
            {
                if (!logEventFilter.IsEnabled(logEvent))
                {
                    return;
                }
            }

            _sink.Emit(logEvent);
        }
コード例 #9
0
        public void Emit(LogEvent logEvent)
        {
            // If you like this, you might like Serilog.Expressions even better :)
            // https://github.com/serilog/serilog-expressions

            var newTimestamp = logEvent.Timestamp.AddHours(-5);

            var newLogEvent = new LogEvent(newTimestamp, logEvent.Level, logEvent.Exception, logEvent.MessageTemplate,
                                           logEvent.Properties.Select(p => new LogEventProperty(p.Key, p.Value)));

            _targetSink.Emit(newLogEvent);
        }
コード例 #10
0
        public void Emit(LogEvent logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            if ((int)logEvent.Level < (int)_levelSwitch.MinimumLevel)
            {
                return;
            }

            _sink.Emit(logEvent);
        }
コード例 #11
0
        public void Emit(LogEvent logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException("logEvent");
            }

            if (logEvent.Level < _restrictedMinimumLevel)
            {
                return;
            }

            _sink.Emit(logEvent);
        }
コード例 #12
0
 void Pump()
 {
     try
     {
         foreach (var next in _queue.GetConsumingEnumerable())
         {
             _pipeline.Emit(next);
         }
     }
     catch (Exception ex)
     {
         SelfLog.WriteLine("{0} fatal error in worker thread: {1}", typeof(BackgroundWorkerSink), ex);
     }
 }
コード例 #13
0
        void Dispatch(LogEvent logEvent)
        {
            // The enricher may be a "safe" aggregate one, but is most commonly bare and so
            // the exception handling from SafeAggregateEnricher is duplicated here.
            try
            {
                _enricher.Enrich(logEvent, _messageTemplateProcessor);
            }
            catch (Exception ex)
            {
                SelfLog.WriteLine("Exception {0} caught while enriching {1} with {2}.", ex, logEvent, _enricher);
            }

            _sink.Emit(logEvent);
        }
コード例 #14
0
ファイル: Logger.cs プロジェクト: nickvane/serilog
        void Dispatch(LogEvent logEvent)
        {
            foreach (var enricher in _enrichers)
            {
                try
                {
                    enricher.Enrich(logEvent, _messageTemplateProcessor);
                }
                catch (Exception ex)
                {
                    SelfLog.WriteLine("Exception {0} caught while enriching {1} with {2}.", ex, logEvent, enricher);
                }
            }

            _sink.Emit(logEvent);
        }
コード例 #15
0
        public void Emit(LogEvent logEvent)
        {
            try
            {
                foreach (var logEventFilter in _filters)
                {
                    if (!logEventFilter.IsEnabled(logEvent))
                    {
                        return;
                    }
                }

                _sink.Emit(logEvent);
            }
            catch (Exception ex)
            {
                SelfLog.WriteLine("Caught exception {0} while applying filters.", ex);
            }
        }
コード例 #16
0
        public void Emit(LogEvent logEvent)
        {
            ScanForDeadRequests();
            LogEventPropertyValue requestIdValue;

            if (logEvent.Properties.TryGetValue(_requestIdProperty, out requestIdValue))
            {
                string requestId = requestIdValue.ToString(null, null).Replace("\"", string.Empty);
                var    buffer    = GetOrCreateRequestBuffer(requestId);
                buffer.LogEvent(logEvent);
            }
            else
            {
                if (_eventLevel.IsSatisifedBy(logEvent.Level))
                {
                    _sink.Emit(logEvent);
                }
            }
        }
コード例 #17
0
 void Pump()
 {
     try
     {
         foreach (var next in _queue.GetConsumingEnumerable())
         {
             try
             {
                 _wrappedSink.Emit(next);
             }
             catch (Exception ex)
             {
                 SelfLog.WriteLine("{0} failed to emit event to wrapped sink: {1}", typeof(BackgroundWorkerSink), ex);
             }
         }
     }
     catch (Exception fatal)
     {
         SelfLog.WriteLine("{0} fatal error in worker thread: {1}", typeof(BackgroundWorkerSink), fatal);
     }
 }
コード例 #18
0
        /// <inheritdoc />
        /// <summary>
        ///     Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent"> The log event to write. </param>
        /// <remarks>
        ///     Events that come in out-of-order (e.g. around the rollovers) may end up written to a
        ///     later file than their timestamp would indicate.
        /// </remarks>
        public void Emit(LogEvent logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            lock (_syncRoot)
            {
                if (_isDisposed)
                {
                    throw new ObjectDisposedException("The rolling log file has been disposed.");
                }

                AlignCurrentFileTo(logEvent);

                // If the file was unable to be opened on the last attempt, it will remain null until
                // the next checkpoint passes, at which time another attempt will be made to open it.
                _currentFile?.Emit(logEvent);
            }
        }
コード例 #19
0
        private async Task PumpAsync()
        {
            try
            {
                while (await _channel.Reader.WaitToReadAsync())
                {
                    var logEvent = await _channel.Reader.ReadAsync();

                    try
                    {
                        _wrappedSink.Emit(logEvent);
                    }
                    catch (Exception ex)
                    {
                        SelfLog.WriteLine("{0} failed to emit event to wrapped sink: {1}", typeof(BackgroundWorkerSink), ex);
                    }
                }
            }
            catch (Exception fatal)
            {
                SelfLog.WriteLine("{0} fatal error in worker thread: {1}", typeof(BackgroundWorkerSink), fatal);
            }
        }
コード例 #20
0
 public void Emit(LogEvent logEvent)
 {
     _sink.Emit(logEvent);
 }
        public void Emit <T>(Event <T> evt)
        {
            var nativeEvent = _mapper.Map(evt);

            _sink.Emit(nativeEvent);
        }
コード例 #22
0
 public void Emit(LogEvent logEvent)
 {
     Emitted.Add(logEvent);
     _sink.Emit(logEvent);
 }
コード例 #23
0
 /// <inheritdoc />
 public void Emit(LogEvent logEvent)
 {
     _sink.Emit(logEvent);
     Interlocked.Exchange(ref _flushRequired, 1);
 }
コード例 #24
0
 /// <inheritdoc />
 public void Emit(LogEvent logEvent) =>
 sink.Emit(logEvent);