Skip to content

Commit

Permalink
Server Response can be null in callback
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Apr 9, 2024
1 parent 46a70f1 commit 344e18b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Elastic.NLog.Targets/ElasticsearchTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,18 @@ public InternalLoggerCallbackListener()
};
ExportResponseCallback = (response, _) =>
{
if (response is null)
return;

if (response.TryGetElasticsearchServerError(out var error))
NLog.Common.InternalLogger.Error("ElasticSearch - Server Response Error - {0}", error);
foreach (var itemResult in response.Items)
if (itemResult.Status >= 300)
NLog.Common.InternalLogger.Error("ElasticSearch - Failed to {0} document status {1} - {2}", itemResult.Action, itemResult.Status, itemResult.Error);

if (response.Items?.Count > 0)
{
foreach (var itemResult in response.Items)
if (itemResult.Status >= 300)
NLog.Common.InternalLogger.Error("ElasticSearch - Failed to {0} document status {1} - {2}", itemResult.Action, itemResult.Status, itemResult.Error);
}
};
}
}
Expand Down

0 comments on commit 344e18b

Please sign in to comment.