[英]Serilog Correlate Log Messages package not compatible with asp.net core
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 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 package 以及
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 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需要Serilog.Sinks.Elasticsearch 。 You need configure your Program.cs to configure the serilog, here a complete example.你需要配置你的 Program.cs 来配置 serilog, 这里是一个完整的例子。 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().并在您的构建器中添加.UseSerilog()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.