I'm using a package "SerilogWeb.Classic" for Correlating log messages, but the package is not compatible with asp.net core, could you please guide me an alternative package, also I'm looking for Serilog metrics, could you please guide me for that package as well
var log = new LoggerConfiguration()
.WriteTo.Console()
.Enrich.WithHttpRequestId() // coming from SerilogWeb.Classic lib
.Enrich.WithUserName()
.CreateLogger();
You can use the default log system of .net core Microsoft.Logging
and in the startup configure the serilog, to do that you can use the package Serilog and Serilog.AspNetCore and the sinks packages to write somewhere, in your case to write into elasticsearch you need the Serilog.Sinks.Elasticsearch . You need configure your Program.cs to configure the serilog, here a complete example. But basically you need add:
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(configuration["ElasticConfiguration:Uri"]))
{
AutoRegisterTemplate = true,
IndexFormat = $"{Assembly.GetExecutingAssembly().GetName().Name.ToLower()}-{DateTime.UtcNow:yyyy-MM}"
})
.Enrich.WithProperty("Environment", environment)
.ReadFrom.Configuration(configuration)
.CreateLogger();
And in your builder add.UseSerilog().
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.