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);
});