private async Task Send(IEnumerable <LogEvent> events) { string allEvents = string.Empty; foreach (var logEvent in events) { var sw = new StringWriter(); _jsonFormatter.Format(logEvent, sw); var serialisedEvent = sw.ToString(); var splunkEvent = new SplunkEvent(serialisedEvent, _source, _sourceType, _host, _index, logEvent.Timestamp.ToEpoch()); allEvents = $"{allEvents}{splunkEvent.Payload}"; } var request = new EventCollectorRequest(_splunkHost, allEvents); var response = await _httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { //Do Nothing? } else { //Application Errors sent via HTTP Event Collector if (HttpEventCollectorApplicationErrors.Any(x => x == response.StatusCode)) { SelfLog.WriteLine( "A status code of {0} was received when attempting to send to {1}. The event has been discarded and will not be placed back in the queue.", response.StatusCode.ToString(), _splunkHost); } else { //Put the item back in the queue & retry on next go SelfLog.WriteLine( "A status code of {0} was received when attempting to send to {1}. The event has been placed back in the queue", response.StatusCode.ToString(), _splunkHost); foreach (var logEvent in events) { _queue.Enqueue(logEvent); } } } }
private async Task Send(IEnumerable <LogEvent> events) { var allEvents = new StringWriter(); foreach (var logEvent in events) { _jsonFormatter.Format(logEvent, allEvents); } var request = new EventCollectorRequest(_splunkHost, allEvents.ToString(), _uriPath); var response = await _httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { //Do Nothing? } else { //Application Errors sent via HTTP Event Collector if (HttpEventCollectorApplicationErrors.Any(x => x == response.StatusCode)) { SelfLog.WriteLine( "A status code of {0} was received when attempting to send to {1}. The event has been discarded and will not be placed back in the queue.", response.StatusCode.ToString(), _splunkHost); } else { //Put the item back in the queue & retry on next go SelfLog.WriteLine( "A status code of {0} was received when attempting to send to {1}. The event has been placed back in the queue", response.StatusCode.ToString(), _splunkHost); foreach (var logEvent in events) { _queue.Enqueue(logEvent); } } } }