2 回答

TA贡献1843条经验 获得超7个赞
最后,我通过添加操作过滤器并向 Serilog 的 LogContext 添加属性来修复此问题,如下所示:
public class LoggingPropertiesFilter : IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
// Do something before the action executes.
ControllerBase controllerBase = context.Controller as ControllerBase;
if(controllerBase != null)
{
var routeAction = controllerBase.RouteData.Values["action"];
LogContext.PushProperty("method", routeAction);
}
}
public void OnActionExecuted(ActionExecutedContext context)
{
// Do something after the action executes.
}
}
到目前为止,我遇到的唯一问题是我必须手动为每个操作附加一个属性才能使其工作,但这确实解决了我遇到的最初问题(如果它对任何人都有用的话)。
- 2 回答
- 0 关注
- 122 浏览
添加回答
举报