'How to get the response from Serilog.Skinks.Elasticsearch

What is the correct way to handle transaction errors that might appear when using Serilog.Sinks.Elasticsearch? I thought the ElasticsearchSinkOptions.EmitEventFailure setting would help me there, but it didn't trigger.

Here is my ElasticsearchSinkOptions:

            ElasticsearchSinkOptions sinkOptions= new(new Uri("http://127.0.0.1:9200"))
            {
                EmitEventFailure = EmitEventFailureHandling.RaiseCallback,
                FailureCallback = (LogEvent x) => MessageBox.Show("ERROR"),
            };

            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Information()
                .WriteTo.Elasticsearch(sinkOptions)
                .CreateLogger();

The message box never pops up. I also tried using EmitEventFailureHandling.ThrowException but no exception was thrown.

Background: Yesterday no more logs appeared in my ES. I did not receive any exceptions. Only when trying to manually add a new log message using REST I received the following response:

"reason": "Validation Failed: 1: this action would add [2] shards, but this cluster currently has [1000]/[1000] maximum normal shards open;"

I expected the sink showing me some kind of response.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source