From a01baffec9a74a06ab7d1beb5791e98da9989c3e Mon Sep 17 00:00:00 2001 From: Tommy Kindmark Date: Tue, 4 Apr 2023 13:54:17 +0200 Subject: [PATCH] Added original exception to FailureCallback action (#449) --- sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs | 2 +- .../Sinks/ElasticSearch/ElasticSearchSink.cs | 4 ++-- .../Sinks/ElasticSearch/ElasticsearchSinkOptions.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs b/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs index 765d0c86..41a9c355 100644 --- a/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs +++ b/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs @@ -40,7 +40,7 @@ static void Main(string[] args) NumberOfShards = 2, //BufferBaseFilename = "./buffer", // RegisterTemplateFailure = RegisterTemplateRecovery.FailSink, - FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate), + FailureCallback = (e, ex) => Console.WriteLine("Unable to submit event " + e.MessageTemplate), EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog | EmitEventFailureHandling.WriteToFailureSink | EmitEventFailureHandling.RaiseCallback, diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs index 52c0871d..35d8f4e7 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs @@ -142,7 +142,7 @@ private void HandleException(Exception ex, IEnumerable events) { foreach (var e in events) { - _state.Options.FailureCallback(e); + _state.Options.FailureCallback(e, ex); } } catch (Exception exCallback) @@ -233,7 +233,7 @@ private void HandleResponse(IEnumerable events, DynamicResponse result // Send to a failure callback try { - _state.Options.FailureCallback(e); + _state.Options.FailureCallback(e, null); } catch (Exception ex) { diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs index f759be2e..f15579d8 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs @@ -246,7 +246,7 @@ public class ElasticsearchSinkOptions /// A callback which can be used to handle logevents which are not submitted to Elasticsearch /// like when it is unable to accept the events. This is optional and depends on the EmitEventFailure setting. /// - public Action FailureCallback { get; set; } + public Action FailureCallback { get; set; } /// /// The maximum number of events that will be held in-memory while waiting to ship them to