You’ll need to make sure you have the following packages installed:
- Serilog
- Serilog.Extensions.Hosting (this provides the
.UseSerilog
extension method. If you have the Serilog.AspNetCore package, you do not need to explicitly include this)
Then you’ll need a using
:
using Serilog;
Which should allow you to access .UseSerilog
via builder.Host
:
using Serilog;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog();
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();
You can use a different overload to get the hosting context, services, and configuration. From there you can configure sinks, etc.:
builder.Host.UseSerilog((hostContext, services, configuration) => {
configuration.WriteTo.Console();
});