C
C#15mo ago
khamas

❔ serilog mongodb not logging extra properties

So I have set up a mongodb sink on serilog, but extra properties are not getting saved...
Log.Logger = new LoggerConfiguration()
.WriteTo.MongoDB(
database: myDatabase,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error,
collectionName: "error_logs",
period: TimeSpan.FromSeconds(30))
.CreateLogger();

builder.Host.UseSerilog();

var app = builder.Build();

app.UseSerilogRequestLogging(x =>
{
x.IncludeQueryInRequestPath = true;
x.GetLevel = (httpContext, elapsed, ex) => LogEventLevel.Error;
x.Logger = Log.Logger;
x.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
{
diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value);
diagnosticContext.Set("RequestForm", httpContext.Request.Form);
diagnosticContext.Set("RequestScheme", httpContext.Request.Scheme);
};
});
Log.Logger = new LoggerConfiguration()
.WriteTo.MongoDB(
database: myDatabase,
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error,
collectionName: "error_logs",
period: TimeSpan.FromSeconds(30))
.CreateLogger();

builder.Host.UseSerilog();

var app = builder.Build();

app.UseSerilogRequestLogging(x =>
{
x.IncludeQueryInRequestPath = true;
x.GetLevel = (httpContext, elapsed, ex) => LogEventLevel.Error;
x.Logger = Log.Logger;
x.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
{
diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value);
diagnosticContext.Set("RequestForm", httpContext.Request.Form);
diagnosticContext.Set("RequestScheme", httpContext.Request.Scheme);
};
});
1 Reply
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.