I'm trying to integrate Serilog and Seq into Visual Studio's .NET 6 Worker Service template, but I can't figure out where to wire up serilog-aspnetcore's UseSerilogRequestLogging extension method.
The template provides this implementation in Program.cs (to which I've added .UseSerilog and .UseWindowsService)
IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args)
.UseSerilog((ctx, lc) => lc
.WriteTo.Console()
.ReadFrom.Configuration(ctx.Configuration))
.UseWindowsService(options => { options.ServiceName = "My Service"; })
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
});
IHost host = hostBuilder.Build();
await host.RunAsync();
My packages
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Expressions" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="5.2.0" />
<PackageReference Include="Twilio.AspNet.Core" Version="6.0.0" />
</ItemGroup>
I can't figure out where to wire up serilog-aspnetcore's UseSerilogRequestLogging extension method.
- Where is my application's IApplicationBuilder? (does it have one?)
- Or is there some other way I need to plug Serilog into the request pipeline?
public static IApplicationBuilder UseSerilogRequestLogging(
this IApplicationBuilder app,
string messageTemplate)