title: Unable to resolve service for type 'Microsoft.Extensions.Logging.ILogger`1[WebApplication1.Startup]'
body: <p>I created an ASP.NET Core 3.0 Web Application with the default template in Visual Studio 2019 Preview 2.2 and tried to inject an ILogger in Startup:</p>
  
  <pre><code>namespace WebApplication1
  {
      public class Startup
      {
          private readonly ILogger _logger;
  
          public Startup(IConfiguration configuration, ILogger&lt;Startup&gt; logger)
          {
              Configuration = configuration;
              _logger = logger;
          }
          // ...
      }
  }
  </code></pre>
  
  <p>In Program.cs I also call the ConfigureLogging() method:</p>
  
  <pre><code>namespace WebApplication1
  {
      public class Program
      {
          public static void Main(string[] args)
          {
              CreateHostBuilder(args).Build().Run();
          }
  
          public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
              Host.CreateDefaultBuilder(args)
                  .ConfigureLogging((hostingContext, logging) =&gt;
                  {
                      logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                      logging.ClearProviders();
                      logging.AddConsole();
                  })
                  .ConfigureWebHostDefaults(webBuilder =&gt;
                  {
                      webBuilder.UseStartup&lt;Startup&gt;();
                  });
      }
  }
  </code></pre>
  
  <p>It works in ASP.NET Core 2.x but in ASP.NET Core 3 it fails with the following error:</p>
  
  <pre><code>System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Extensions.Logging.ILogger`1[WebApplication1.Startup]' while attempting to activate 'WebApplication1.Startup'.
     at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
     at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
     at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
  --- End of stack trace from previous location where exception was thrown ---
     at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostBuilder.&lt;&gt;c__DisplayClass13_0.&lt;UseStartup&gt;b__2(IApplicationBuilder app)
     at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.&lt;&gt;c__DisplayClass2_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
     at Microsoft.AspNetCore.HostFilteringStartupFilter.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
     at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
  </code></pre>
  
  <p>Any idea on what is causing this behavior?</p>
  
  <hr>
  
  <p>Below the full Program.cs and Startup.cs files from the default "Web Application" template, only logging was added.</p>
  
  <p>Program.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.Hosting;
  using Microsoft.Extensions.Logging;
  
  namespace WebApplication1
  {
      public class Program
      {
          public static void Main(string[] args)
          {
              CreateHostBuilder(args).Build().Run();
          }
  
          public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
              Host.CreateDefaultBuilder(args)
                  .ConfigureLogging((hostingContext, logging) =&gt;
                  {
                      logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                      logging.ClearProviders();
                      logging.AddConsole();
                  })
                  .ConfigureWebHostDefaults(webBuilder =&gt;
                  {
                      webBuilder.UseStartup&lt;Startup&gt;();
                  });
      }
  }
  </code></pre>
  
  <p>Startup.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.Http;
  using Microsoft.AspNetCore.HttpsPolicy;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Logging;
  
  namespace WebApplication1
  {
      public class Startup
      {
          private readonly ILogger _logger;
          public Startup(IConfiguration configuration, ILogger&lt;Startup&gt; logger)
          {
              Configuration = configuration;
              _logger = logger;
          }
  
          public IConfiguration Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
              services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
              {
                  // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                  options.CheckConsentNeeded = context =&gt; true;
                  options.MinimumSameSitePolicy = SameSiteMode.None;
              });
  
              //services.AddTransient(typeof(ILogger&lt;&gt;), (typeof(Logger&lt;&gt;)));
  
              services.AddMvc()
                  .AddNewtonsoftJson();
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              else
              {
                  app.UseExceptionHandler("/Error");
                  // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                  app.UseHsts();
              }
  
              app.UseHttpsRedirection();
              app.UseStaticFiles();
  
              app.UseRouting(routes =&gt;
              {
                  routes.MapApplication();
              });
  
              app.UseCookiePolicy();
  
              app.UseAuthorization();
          }
      }
  }
  </code></pre>