小编Sum*_*nto的帖子

Serilog Enrichers 不登录到控制台 (.Net 6.0)

使用(.Net 6.0)我试图输出一些额外的默认信息与所有日志当我输出到控制台时我看不到属性,但是如果我启用 Json 并输出到文件它一切正常,想知道你是否有任何线索?

public class Program
{
    public static int Main(string[] args)
    {

        var builder = WebApplication.CreateBuilder(args);

        Log.Logger = new LoggerConfiguration()
            //.WriteTo.File(new Serilog.Formatting.Json.JsonFormatter(), "Logs/log-.txt", fileSizeLimitBytes: 5242880, rollOnFileSizeLimit: true, rollingInterval: RollingInterval.Day, shared: true)
            .Enrich.FromLogContext()
            .Enrich.WithProcessId()
            .Enrich.WithProcessName()
            .Enrich.WithProperty("Prop1", "ABC123")
            .Enrich.WithProperty("Prop2", "1.00")
            .Enrich.WithProperty("PID", Process.GetCurrentProcess().Id)
            .WriteTo.Console()
            .CreateLogger();


        builder.Host.UseSerilog(); 

        // Add services to the container.

        var app = builder.Build();

        // Configure the HTTP request pipeline.
    
        app.MapGet("/weatherforecast", () =>
        {
            Log.Information("Hello....");
            return forecast;
        });

        try
        {
            app.Run();
        }
        catch (Exception ex)
        {
            ex.ToString();
        }
        finally …
Run Code Online (Sandbox Code Playgroud)

.net c# console serilog

3
推荐指数
1
解决办法
1944
查看次数

标签 统计

.net ×1

c# ×1

console ×1

serilog ×1