title: Global exception handling and Logging in asp.net MVC Core
body: <p>I am new to asp.net core mvc. i need to write Global exception handling and error Logging  in on palce..i dont need to write all below in every controller Please help me to write globally in one place </p>
  
  <p>Here is the my code</p>
  
  <p>using Microsoft.AspNet.Diagnostics;</p>
  
  <pre><code>using Microsoft.AspNet.Http.Features;
  using Microsoft.AspNet.Mvc;
  using Microsoft.Extensions.Logging;
  
  namespace NS.Controllers
  {
      public class HomeController : Controller
      {
          static ILogger _logger;
          public HomeController(ILoggerFactory factory)
          {
              if (_logger == null)
                  _logger = factory.Create("Unhandled Error");
          }
  
          public IActionResult Error()
          {
              var feature = HttpContext.Features.Get&lt;IExceptionHandlerFeature&gt;();
              var error = feature?.Error;
              _logger.LogError("Oops!", error);
              return View("~/Views/Shared/Error.cshtml", error);
          }
      }
  }
  </code></pre>