‘Serilog.Extensions.Hosting.DiagnosticContext’ while attempting to activate ‘Serilog.AspNetCore.RequestLoggingMiddleware’

Seems that you are missing .UseSerilog inside Program. Here is my template for Program:

public class Program
{
    public static void Main(string[] args)
    {
        var webHost = CreateHostBuilder(args)
            .Build();

        // access any service from here by using webHost.Services.GetService<...
        
        Log.Information("Starting MyWebApp");

        // ... configure Serilog

        try
        {
          webHost.Run();
        }
        catch (Exception ex)
        {
          Log.Fatal(ex, "The application failed to start correctly.");
        }
        finally
        {
          Log.CloseAndFlush();
        }
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            })
            .UseSerilog();
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)