问题
I want to dynamically add a context value to my error logging in ASP.NET MVC. However I only have this property after a login with success.
Currently I have this setup at my startup.cs:
Log.Logger = new LoggerConfiguration()
//other Enrich settings
.Enrich.WithProperty("AccountID", AccountID)
.CreateLogger();
I have tried to in my solution after a exception to logging:
Log.Information("Adding {AccountID}", AccountID);
And:
using (LogContext.PushProperty("AccountID", AccountID))
{
Log.Information("Adding {AccountID}", AccountID);
}
But nothing solve actually the problem. Someone have more options/ways to resolve this issue?
来源:https://stackoverflow.com/questions/62487408/adding-contextual-properties-to-serilog-logging-of-exceptions