I'm using Serilog
with Elasticsearch sink with the configurations like this:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.MinimumLevel.Override("Microsoft", LogEventLevel.Verbose)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.Enrich.WithProperty("Application", "abc")
.Enrich.WithProperty("Environment", env.EnvironmentName)
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(Configuration["LoggingEndpoint"]))
{
AutoRegisterTemplate = true,
CustomFormatter = new ExceptionAsObjectJsonFormatter(renderMessage: true) // Better formatting for exceptions
})
// and later:
services.AddLogging(loggingBuilder =>
loggingBuilder.AddSerilog());
But I can see every log twice, with a couple of milliseconds difference in their timestamp, on the Kibana. I tried the solutions provided here, just in case they might help, but no luck.
By default, serilog will only log to the console.
For example, if you are using Serilog you should configure Log. Logger and LibLog will use it. Also you can disable logging by setting LogProvider. IsDisabled to true . "
Serilog. Context. LogContext can be used to dynamically add and remove properties from the ambient "execution context"; for example, all messages written during a transaction might carry the id of that transaction, and so-on.
Structured logging is a modern approach where logging events are treated as structured data rather than text, for example: { “payload”: { “order”: { “id”: 10 }, “message”: “OrderId: 10 placed successfully” }
This is probably the case because you are configuring Serilog inside your appsettings.json and also inside code. This wil Log everything twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With