Write Serilog events to skywalking apm
- 集成SkyAPM.Agent.AspNetCore
- 集成Serilog.AspNetCore
- 安装nuget包
Serilog.Sinks.Skywalking
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog((context, services, configuration) =>
{
configuration
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Skywalking(services) //添加这一行
.WriteTo.Console();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
或者在 MiniApi
项目中
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((context, services, configuration) =>
{
configuration
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Skywalking(services) //添加这一行
.WriteTo.Console();
});
自定义Formater
configuration
.WriteTo.Skywalking(services, new JsonFormatter())
更多Formatter实现查看Serilog文档,或自行实现ITextFormatter