exception is occuring when elastic server is missing

229 Views Asked by At

Below is the code for serilog elastic search.It's working perfectly when elastic service is running but fails when the server is not available

 .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200/")) // humio elastic bulk endpoint
                        {
                            AutoRegisterTemplate = true,
                            OverwriteTemplate = true,
                            DetectElasticsearchVersion = true,
                            AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
                            NumberOfReplicas = 1,
                            NumberOfShards = 2,
                            RegisterTemplateFailure = RegisterTemplateRecovery.FailSink,
                            FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate),
                            EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog |
                                               EmitEventFailureHandling.WriteToFailureSink |
                                               EmitEventFailureHandling.RaiseCallback,
                            //FailureSink = new FileSink("./fail-{Date}.txt", new JsonFormatter(), null, null)
                            //ModifyConnectionSettings = x => x.BasicAuthentication(username: "", password: "88WS28JEuB0G2WC3cYufdgTINAxOGQvliBrqH5Vqutjb")  // password is ingest token from humio
                        })

exception is occuring when elastic server is missing

Elasticsearch.Net.ElasticsearchClientException: 'No connection could be made because the target machine actively refused it.. Call: Status code unknown from: GET /_cat/nodes?h=v'

HttpRequestException: No connection could be made because the target machine actively refused it.
SocketException: No connection could be made because the target machine actively refused it.

This exception was originally thrown at this call stack:
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
System.Net.Http.ConnectHelper.ConnectAsync(string, int, System.Threading.CancellationToken)
0

There are 0 best solutions below