I have this project made from core 3.1 and upgrading to 6 but I'm having problems with the obsolete UseSerilog() method. With the new minimal WebApplication.CreateBuilder, UseSerilog() now requires builder.Host and my problem is that UserKestrel() uses builder.WebHost.
Are there any workaround to do this? I tried below code: using builder.WebHost and builder.Host in the same builder to setup both but I don't know if there are any downsides.
var builder = WebApplication.CreateBuilder(args);
builder.Services.RegisterServices(builder.Configuration);
builder.WebHost
.UseKestrel(options => options.AddServerHeader = false)
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
Console.WriteLine($@"Application: {env.ApplicationName}");
Console.WriteLine($@"Environment: {env.EnvironmentName}");
config.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", false, true, new[] { "ConnectionStrings:ConString" })
.AddJsonFile($"appsettings.{env.EnvironmentName.ToLowerInvariant()}.json", true, true)
.AddEnvironmentVariables("ASPNETCORE_");
})
.UseIISIntegration()
.CaptureStartupErrors(false)
.UseHealthChecks("/healthcheck");
builder.Host.UseSerilog((ctx, lc) => lc.ReadFrom.Configuration(ctx.Configuration));
var app = builder.Build();
app.Run();