title: ASP.NET Core AsyncActionFilter to log ActionArguments and Result
body: <p>I am looking to create a filter implementing <code>IAsyncActionFilter</code> that will retrieve data from the current request's context's <code>ActionParameters</code> and its <code>Result</code>. I'm using a custom attribute <code>MyLogAttribute</code> to direct the logging beheavior, e.g. to opt-in for logging and indicating fields with critical information.</p>
  
  <pre><code>public class AsyncMyLogFilter : IAsyncActionFilter
  {
      public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
      {
          var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
  
          if (actionDescriptor != null)
          {
              var attribute = actionDescriptor.MethodInfo.GetCustomAttribute&lt;MyLogAttribute&gt;();
  
              if (attribute != null)
              {
  
                  await next();
  
                  // This is where the magic is supposed to happen:
                  LoggerHelper.Log(context.ActionArguments, context.Result);
              }
  
              return;
          }
  
          await next();
      }
  }
  </code></pre>
  
  <p>The way the filter provides a <code>next()</code> delegate led me to believe that past that point the action would be completed and the result object available for inspection as an <code>ObjectResult</code>. However, while the filter is able to grab the <code>ActionArguments</code> without problem, the <code>Result</code> property is unfortunately just null, which is not helpful at all.</p>
  
  <p>The obvious alternative, the synchronous <code>IActionFilter</code>, lets me examine the <code>Result</code> object on the <code>OnActionExecuted</code> stage, but at this point the <code>ActionArguments</code> dictionary is not available.</p>
  
  <p>So, is there any way to access both <code>ActionArguments</code> and <code>Result</code> within the same method scope?</p>
  
  <p>-S</p>