serilog-contrib / serilog-sinks-elasticsearch

A Serilog sink that writes events to Elasticsearch
Apache License 2.0
433 stars 197 forks source link

Unable to upload logs to Elastic Search Cloud #564

Closed PaulMcCaffery closed 1 year ago

PaulMcCaffery commented 1 year ago

A few questions before you begin:

Hello,

I am using .NET 7 and Serilog elastic search 9.0.3.

I am trying to integrate with a newly setup Elastic Search cloud instance.

The Serilog is logging to file and to my buffer. I did notice the fail-{Date}.txt file also containing some logs but this has since stopped logging.

The logs are not being added to elastic when I would expect them to.

Is there any additional elastic setup required to enable integrations or can I simply supply the endpoint URI of my elastic search and enable basic auth using username and password and I am good to go?

My startup code contains the following:

Log.Logger = new LoggerConfiguration()
                .Enrich.FromLogContext()
                .Enrich.WithMachineName()
                .WriteTo.File("logs\\phonicstracker.log",
                            Serilog.Events.LogEventLevel.Debug,
                            rollOnFileSizeLimit: true,
                            fileSizeLimitBytes: 104857600)
                .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("https://companyname.es.uksouth.azure.elastic-cloud.com:443"))
                {
                    AutoRegisterTemplate = true,
                    OverwriteTemplate = true,
                    DetectElasticsearchVersion = true,
                    AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv8,
                    NumberOfReplicas = 1,
                    NumberOfShards = 2,
                    BufferBaseFilename = "./logs/buffer",
                    RegisterTemplateFailure = RegisterTemplateRecovery.FailSink,                    
                    EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog |
                                       EmitEventFailureHandling.WriteToFailureSink |
                                       EmitEventFailureHandling.RaiseCallback,
                    FailureSink = new FileSink("./logs/fail-{Date}.txt", new JsonFormatter(), 100000, null),
                    MinimumLogEventLevel = Serilog.Events.LogEventLevel.Information,
                    ModifyConnectionSettings = x => x.BasicAuthentication("elastic", "***"),
                }).CreateLogger();

            Log.Information("Hello World");

Also the file name for the failure sink does replace {Date} so this file could grow. Is this correct above?

Any help would be appreciated.

PaulMcCaffery commented 1 year ago

I was being an idiot, it was logging just fine.