Ejemplo n.º 1
0
        public static async Task <int> ShipEvents(
            SeqConnection connection,
            ILogEventReader reader,
            List <ILogEventEnricher> enrichers,
            InvalidDataHandling invalidDataHandling,
            SendFailureHandling sendFailureHandling,
            Func <LogEvent, bool> filter = null)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (enrichers == null)
            {
                throw new ArgumentNullException(nameof(enrichers));
            }

            var batch = await ReadBatchAsync(reader, filter, BatchSize, invalidDataHandling);

            while (true)
            {
                var sendSucceeded = false;
                try
                {
                    sendSucceeded = await SendBatchAsync(
                        connection,
                        batch.LogEvents,
                        enrichers,
                        sendFailureHandling != SendFailureHandling.Ignore);
                }
                catch (Exception ex)
                {
                    if (sendFailureHandling != SendFailureHandling.Ignore)
                    {
                        Log.Error(ex, "Failed to send an event batch");
                    }
                }

                if (!sendSucceeded && sendFailureHandling == SendFailureHandling.Fail)
                {
                    return(1);
                }

                if (batch.IsLast)
                {
                    break;
                }

                batch = await ReadBatchAsync(reader, filter, BatchSize, invalidDataHandling);
            }

            return(0);
        }
Ejemplo n.º 2
0
        public static async Task <int> ShipEvents(
            SeqConnection connection,
            string apiKey,
            ILogEventReader reader,
            InvalidDataHandling invalidDataHandling,
            SendFailureHandling sendFailureHandling,
            int batchSize,
            Func <LogEvent, bool> filter = null)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var batch = await ReadBatchAsync(reader, filter, batchSize, invalidDataHandling);

            var retries = 0;

            while (true)
            {
                var sendSucceeded = false;
                try
                {
                    sendSucceeded = await SendBatchAsync(
                        connection,
                        apiKey,
                        batch.LogEvents,
                        sendFailureHandling != SendFailureHandling.Ignore);
                }
                catch (Exception ex)
                {
                    if (sendFailureHandling != SendFailureHandling.Ignore)
                    {
                        Log.Error(ex, "Failed to send an event batch");
                    }
                }

                if (!sendSucceeded)
                {
                    if (sendFailureHandling == SendFailureHandling.Fail)
                    {
                        return(1);
                    }

                    if (sendFailureHandling == SendFailureHandling.Retry)
                    {
                        var millisecondsDelay = (int)Math.Min(Math.Pow(2, retries) * 2000, 60000);
                        await Task.Delay(millisecondsDelay);

                        retries += 1;
                        continue;
                    }
                }

                retries = 0;

                if (batch.IsLast)
                {
                    break;
                }

                batch = await ReadBatchAsync(reader, filter, batchSize, invalidDataHandling);
            }

            return(0);
        }
Ejemplo n.º 3
0
 public override void Enable(OptionSet options)
 {
     options.Add("send-failure=",
                 "Specify how connection failures are handled: `fail` (default), `continue`, or `ignore`",
                 v => SendFailureHandling = (SendFailureHandling)Enum.Parse(typeof(SendFailureHandling), v, ignoreCase: true));
 }