Adding contextual properties to Serilog logging of exceptions

筅森魡賤 提交于 2021-01-28 21:10:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!