簡體   English   中英

Serilog 關聯日志消息 package 與 asp.net 內核不兼容

[英]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 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需要Serilog.Sinks.Elasticsearch 你需要配置你的 Program.cs 來配置 serilog, 這里是一個完整的例子。 但基本上你需要添加:

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();

並在您的構建器中添加.UseSerilog()。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM