title: How can I make my code more reusable for logging in my controllers
body: <p>I am using same code for every controller. OnActionExecuting is called every time before action executed.
  how can i refactor the given code?</p>
  <pre><code>public class HomeController : Controller
      {
  
          private readonly ILogger&lt;AccountController&gt; logger;
          private string userId;
          private string path;
  
          public AccountController(
              ILogger&lt;AccountController&gt; logger)
          {
              this.logger = logger;
          }
  
          public override void OnActionExecuting(ActionExecutingContext context)
          {
              userId =  User.FindFirstValue(ClaimTypes.NameIdentifier) 
              path = $&quot;{context.HttpContext.Request.Path.Value}[{context.HttpContext.Request.Method}]&quot;;
              logger.LogDebug($&quot;{path} started. User(id): {userId}.&quot;);
          }
  }
  </code></pre>
  <p>Example of how i am using it:</p>
  <pre><code>logger.LogInformation($&quot;{path} Was approved for User(id) + {userId}.&quot;);
  </code></pre>