Skip to content

Commit

Permalink
Add more protections against null during self logging exceptions in S…
Browse files Browse the repository at this point in the history
…erilog as reported in #341 (#370)
  • Loading branch information
Mpdreamz authored Apr 10, 2024
1 parent 2a30636 commit 88cbf7d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Elastic.Serilog.Sinks/ElasticsearchSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ public SelfLogCallbackListener(ElasticsearchSinkOptions<TEcsDocument> options)
};
ExportResponseCallback = (response, _) =>
{
var errorItems = response.Items.Where(i => i.Status >= 300).ToList();
if (response == null) return;

if (response.TryGetElasticsearchServerError(out var error))
SelfLog.WriteLine("{0}", error);
// ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
var errorItems = response.Items?.Where(i => i.Status >= 300).ToArray() ?? Array.Empty<BulkResponseItem>();
foreach (var errorItem in errorItems)
SelfLog.WriteLine("{0}", $"Failed to {errorItem.Action} document status: ${errorItem.Status}, error: ${errorItem.Error}");

Expand Down

0 comments on commit 88cbf7d

Please sign in to comment.