title: Logging and configuration for .Net core 2.0 console application?
body: <p>The following code got the errors. What's the right way to setup logging and configuration management for .Net Core 2.0 console application?</p>
  
  <blockquote>
    <p>Error CS1061  'LoggerFactory' does not contain a definition for 'AddConsole' and no extension method 'AddConsole' accepting a first argument of type 'LoggerFactory' could be found (are you missing a using directive or an assembly reference?) </p>
    
    <p>Error CS1503  Argument 2: cannot convert from 'Microsoft.Extensions.Configuration.IConfigurationSection' to 'System.Action'  </p>
  </blockquote>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          var services = new ServiceCollection();
          ConfigureServices(services);
          var serviceProvider = services.BuildServiceProvider();
          var app = serviceProvider.GetService&lt;Application&gt;();
          Task.Run(() =&gt; app.Run()).Wait();
      }
  
      private static void ConfigureServices(IServiceCollection services)
      {
          ILoggerFactory loggerFactory = new LoggerFactory()
              .AddConsole() // Error!
              .AddDebug();
  
          services.AddSingleton(loggerFactory); // Add first my already configured instance
          services.AddLogging(); // Allow ILogger&lt;T&gt;
  
          IConfigurationRoot configuration = GetConfiguration();
          services.AddSingleton&lt;IConfigurationRoot&gt;(configuration);
  
          // Support typed Options
          services.AddOptions();
          services.Configure&lt;MyOptions&gt;(configuration.GetSection("MyOptions")); // Error!
  
          services.AddTransient&lt;Application&gt;();
      }
  
      private static IConfigurationRoot GetConfiguration()
      {
          return new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddXmlFile("App.config", optional: true).Build();
      }
  
      public class MyOptions
      {
          public string Name { get; set; }
      }
  
      public class Application
      {
          ILogger _logger;
          MyOptions _settings;
  
          public Application(ILogger&lt;Application&gt; logger, IOptions&lt;MyOptions&gt; settings)
          {
              _logger = logger;
              _settings = settings.Value;
          }
  
          public async Task Run()
          {
              try
              {
                  _logger.LogInformation($"This is a console application for {_settings.Name}");
              }
              catch (Exception ex)
              {
                  _logger.LogError(ex.ToString());
              }
          }
      }
  }
  </code></pre>