ASP.Net Boilerplate with .NET 8 and Serilog

172 Views Asked by At

We tried to update to ASP.NET Boilerplate to the newest version and .NET 8. This works fine except that we are using Serilog instead of the default logger.

We tried to do the hosting with

 WebHost.CreateDefaultBuilder(args)
 .UseKestrel().UseWebRoot(configuration.Host.WwwRootFolder)
 .UseContentRoot(ConfigHelpers.ExeDirectory)
 //.UseSerilog(Serilog.Log.Logger)  <-- this line is not working anymore
 .UseStartup<Startup>(sp => new Startup(monitorLoggingRepository))
 .Build();

My approach was to switch over to WebApplication:

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(options =>
        {
            ...
        }
    )
    .UseWebRoot(configuration.Host.WwwRootFolder);

var startup = new Startup(monitorLoggingRepository);
startup.ConfigureServices(builder.Services);
var host = builder.Host
   .UseContentRoot(ConfigHelpers.ExeDirectory)
   .UseSerilog(Serilog.Log.Logger);
var app = builder.Build();

startup.Configure(app, app.Environment, app.Logger);

By then I'm getting many errors regarding instances which can't be loaded:

Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Routing.Matching.DfaMatcherBuilder Lifetime: Transient ImplementationType: Microsoft.AspNetCore.Routing.Matching.DfaMatcherBuilder': Unable to resolve service for type 'Abp.Dependency.IocManager'

Any ideas how to solve this issue?

0

There are 0 best solutions below