diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs index 6b2d45bf..2fc6b14b 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs @@ -35,7 +35,7 @@ public async Task<SentPayloadResult> SendPayloadAsync(List<string> payload) return await SendPayloadAsync(payload, true); } - public async Task<SentPayloadResult> SendPayloadAsync(List<string> payload,bool first) + public async Task<SentPayloadResult> SendPayloadAsync(List<string> payload, bool first) { try { @@ -45,10 +45,10 @@ public async Task<SentPayloadResult> SendPayloadAsync(List<string> payload,bool if (response.Success) { var cleanPayload = new List<string>(); - var invalidPayload = GetInvalidPayloadAsync(response, payload,out cleanPayload); - if ((cleanPayload?.Any() ?? false) && first) + var invalidPayload = GetInvalidPayloadAsync(response, payload, out cleanPayload); + if ((cleanPayload?.Any() == false) && first) { - await SendPayloadAsync(cleanPayload,false); + await SendPayloadAsync(cleanPayload, false); } return new SentPayloadResult(response, true, invalidPayload); @@ -85,7 +85,8 @@ private InvalidResult GetInvalidPayloadAsync(DynamicResponse baseResult, List<st bool hasErrors = false; foreach (dynamic item in items) { - long? status = item.index?.status; + var itemIndex = item?["index"]; + long? status = itemIndex?["status"]; i++; if (!status.HasValue || status < 300) { @@ -93,8 +94,8 @@ private InvalidResult GetInvalidPayloadAsync(DynamicResponse baseResult, List<st } hasErrors = true; - var id = item.index?._id; - var error = item.index?.error; + var id = itemIndex?["_id"]; + var error = itemIndex?["error"]; if (int.TryParse(id.Split('_')[0], out int index)) { SelfLog.WriteLine("Received failed ElasticSearch shipping result {0}: {1}. Failed payload : {2}.", status, error?.ToString(), payload.ElementAt(index * 2 + 1));