public override void OnActionExecuted(ActionExecutedContext context) { if (context.Controller.GetType().GetCustomAttribute <NoLogAttribute>() != null) { return; } if (IsLogOutPut) { var timeSpan = (long)(DateTime.Now - _startTime).TotalMilliseconds / 1000.0; var requestRoute = context.HttpContext.Request.Path + context.HttpContext.Request.QueryString.ToString(); if (context.Result is JsonResult jsonResult) { HttpLogManager.LogInfo <LogAttribute>(new { ElapsedTime = timeSpan, jsonResult.Value }); } else if (context.Result is ObjectResult objectResult) { HttpLogManager.LogInfo <LogAttribute>(new { ElapsedTime = timeSpan, objectResult.Value }); } else if (context.Result is StatusCodeResult okResult) { HttpLogManager.LogInfo <LogAttribute>(new { ElapsedTime = timeSpan, okResult.StatusCode }); } else if (context.Result is EmptyResult) { HttpLogManager.LogInfo <LogAttribute>(new { ElapsedTime = timeSpan }); } } base.OnActionExecuted(context); }
public override void OnActionExecuting(ActionExecutingContext context) { if (context.Controller.GetType().GetCustomAttribute <NoLogAttribute>() != null) { return; } if (context.ActionArguments != null) { // think: how to exclude the "IFormFile" argument. HttpLogManager.LogInfo <LogAttribute>(context.ActionArguments); } }