使用(.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
{
Log.CloseAndFlush();
}
return 0;
}
}