public void Send(ICollection <LogzioLoggingEvent> logz, BulkSenderOptions options, int attempt = 0)
        {
            if (logz == null || logz.Count == 0)
            {
                return;
            }

            var url = string.Format(UrlTemplate, options.ListenerUrl, options.Token, options.Type);

            try
            {
                using (var client = _webClientFactory.GetWebClient())
                {
                    var serializedLogLines = logz.Select(x => Serialize(x.LogData)).ToArray();
                    var body = String.Join(Environment.NewLine, serializedLogLines);
                    client.UploadString(url, body);
                    if (options.Debug)
                    {
                        _internalLogger.Log("Sent bulk of [{0}] log messages to [{1}] successfully.", logz.Count, url);
                    }
                }
            }
            catch (Exception ex)
            {
                if (options.Debug)
                {
                    _internalLogger.Log("Logzio.DotNet ERROR: " + ex);
                }

                if (attempt < options.RetriesMaxAttempts - 1)
                {
                    Task.Delay(options.RetriesInterval).ContinueWith(task => Send(logz, options, attempt + 1));
                }
            }
        }
Example #2
0
        public Task <HttpResponseMessage> SendAsync(ICollection <LogzioLoggingEvent> logz, BulkSenderOptions options)
        {
            if (logz == null || logz.Count == 0)
            {
                return(Task.FromResult(new HttpResponseMessage(System.Net.HttpStatusCode.OK)));
            }

            var url  = string.Format(UrlTemplate, options.ListenerUrl, options.Token, options.Type);
            var body = SerializeLogEvents(logz, _encodingUtf8);

            return(_httpClient.PostAsync(url, body, _encodingUtf8));
        }
 public Task SendAsync(ICollection <LogzioLoggingEvent> logz, BulkSenderOptions options)
 {
     return(Task.Run(() => Send(logz, options)));
 }
 public ShipperOptions()
 {
     BufferSize        = 100;
     BufferTimeLimit   = TimeSpan.FromSeconds(5);
     BulkSenderOptions = new BulkSenderOptions();
 }