title: How to log the selected ASP.NET Core MVC route?
body: <p>Is there a simple way to log (using nlog, e.g. <code>log.Debug(…)</code>) the selected route in an ASP.NET Core MVC application? I use <code>HttpGet</code>/<code>HttpPost</code> attributes to define my routes, and I am looking for a simple way to log the route that MVC chooses to handle for each incoming request.</p>
  <blockquote>
  <p><strong>Note:</strong> Similar questions have been answered, but they relate to debugging and analyzing routes:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/11473038/how-do-you-debug-mvc-4-api-routes">How do you debug MVC 4 API routes?</a></li>
  <li><a href="https://haacked.com/archive/2008/03/13/url-routing-debugger.aspx/" rel="nofollow noreferrer">ASP.NET Routing Debugger</a></li>
  </ul>
  </blockquote>
  <p>For my purposes, though, I just want to know which route MVC chose to handle for the request and have it logged.  (And, ideally, I don't want to add a log to each controller method; there must be some way to do this once generically for all incoming requests.)</p>