public PeriodicBatchingSink(TimeSpan flushPeriod, Int32?maxQueueSize, IBatchedLogEventSink batchMessagesWriter)
        {
            if (flushPeriod <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(flushPeriod), "must be longer than zero.");
            }
            if (maxQueueSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxQueueSize), "must be a positive number.");
            }
            if (batchMessagesWriter is null)
            {
                throw new ArgumentNullException(nameof(batchMessagesWriter));
            }

            m_currentBatch = new List <LogEvent>();
            m_flushPeriod  = flushPeriod;

            m_batchMessagesWriter = batchMessagesWriter;

            m_messageQueue = maxQueueSize == null ?
                             new BlockingCollection <LogEvent>(new ConcurrentQueue <LogEvent>()) :
                             new BlockingCollection <LogEvent>(new ConcurrentQueue <LogEvent>(), maxQueueSize.Value);

            m_outputStoppingTokenSource = new CancellationTokenSource();
            m_outputTask = Task.Run(() => ProcessLogQueue(m_outputStoppingTokenSource.Token));
            m_outputTask.Wait(50);
        }
Beispiel #2
0
 public BatchingSink(IBatchedLogEventSink sink)
     : base(
         sink,
         new PeriodicBatchingSinkOptions
 {
     BatchSizeLimit = 1000, Period = TimeSpan.FromSeconds(0.5)
 })
 {
 }
Beispiel #3
0
        public ILogEventSink Create(IBatchedLogEventSink sink, MSSqlServerSinkOptions sinkOptions)
        {
            var periodicBatchingSinkOptions = new PeriodicBatchingSinkOptions
            {
                BatchSizeLimit        = sinkOptions.BatchPostingLimit,
                Period                = sinkOptions.BatchPeriod,
                EagerlyEmitFirstEvent = sinkOptions.EagerlyEmitFirstEvent
            };

            return(new PeriodicBatchingSink(sink, periodicBatchingSinkOptions));
        }
Beispiel #4
0
 /// <summary>
 /// Construct a <see cref="PeriodicBatchingSink"/>. New code should avoid subclassing
 /// <see cref="PeriodicBatchingSink"/> and use
 /// <see cref="PeriodicBatchingSink(Serilog.Sinks.PeriodicBatching.IBatchedLogEventSink,Serilog.Sinks.PeriodicBatching.PeriodicBatchingSinkOptions)"/>
 /// instead.
 /// </summary>
 /// <param name="batchSizeLimit">The maximum number of events to include in a single batch.</param>
 /// <param name="period">The time to wait between checking for event batches.</param>
 /// <param name="queueLimit">Maximum number of events in the queue - use <see cref="NoQueueLimit"/> for an unbounded queue.</param>
 protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period, int queueLimit)
     : this(new PeriodicBatchingSinkOptions
 {
     BatchSizeLimit = batchSizeLimit,
     Period = period,
     EagerlyEmitFirstEvent = true,
     QueueLimit = queueLimit
 })
 {
     _batchedLogEventSink = this;
 }
Beispiel #5
0
 /// <summary>
 /// Construct a <see cref="PeriodicBatchingSink"/>.
 /// </summary>
 /// <param name="batchedSink">A <see cref="IBatchedLogEventSink"/> to send log event batches to. Batches and empty
 /// batch notifications will not be sent concurrently. When the <see cref="PeriodicBatchingSink"/> is disposed,
 /// it will dispose this object if possible.</param>
 /// <param name="options">Options controlling behavior of the sink.</param>
 public PeriodicBatchingSink(IBatchedLogEventSink batchedSink, PeriodicBatchingSinkOptions options)
     : this(options)
 {
     _batchedLogEventSink = batchedSink ?? throw new ArgumentNullException(nameof(batchedSink));
 }