C
C#2y 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
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server