title: Register and use a logger with Unity in global.asax
body: <p>I'm using Unity, and I register a logger like this:</p>
  
  <pre><code>public class MvcApplication : System.Web.HttpApplication
  {
      private ILogger _logger;
  
      protected void Application_Start()
      {
          ...
          var container = new UnityContainer();
          container.RegisterType&lt;ILogger, NLogLogger&gt;();
  
          container.RegisterControllers();
  
          DependencyResolver.SetResolver(new UnityDependencyResolver(container));
  
          _logger = container.Resolve&lt;ILogger&gt;();
          _logger.Info("Application started");
      }
  </code></pre>
  
  <p>That seems to work fine - the message is logged.
  Later in the global.asax.cs I have this:</p>
  
  <pre><code>    protected void Application_End()
      {
          _logger.Info("App is shutting down");
      }
  
      protected void Application_Error()
      {
          Exception lastException = Server.GetLastError();
          _logger.Fatal(lastException);
      }
  </code></pre>
  
  <p>However, this throws an exception -  _logger is null. I suspect I'm doing something wrong with Unity - so what's the correct way to use a logger inside global.asax?</p>