79236396

Date: 2024-11-29 08:59:16
Score: 5
Natty:
Report link

I have the same issue now - but i remembered to add the httpcontextaccessor - any idea why it is not logging anything with httpcontext? I even tested with a custom enricher and injected a httpcontextaccessor to it - turned out in the logging context the http context is null?

builder.Services.AddHttpContextAccessor(); 
    
    var sinkOptions = new MSSqlServerSinkOptions
     {
         TableName = "Logs",
         AutoCreateSqlTable = true,
         BatchPostingLimit = 10
     };

    Log.Logger = new LoggerConfiguration()
        .Enrich.FromLogContext()
        .Enrich.WithRequestHeader("X-Platform", "XPlatform")
        .Enrich.WithRequestHeader("X-App-Version")
        .Enrich.WithClientIp()
        .WriteTo.MSSqlServer(
            connectionString: xxx
            columnOptions: new ColumnOptions(),
            sinkOptions: sinkOptions,
            restrictedToMinimumLevel: LogEventLevel.Warning
        )
        .CreateLogger();
    builder.Services.AddLogging(lb =>
    {
        lb.AddSerilog(Log.Logger, true);
    });
Reasons:
  • Blacklisted phrase (1): I have the same issue
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same issue
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: user3526149