title: Logging in Application Insights for .NET Core 2.1 Console app with LoggerFactory
body: <p>I have a .NET Core 2.1 Console application. I have added all the Nuget packages needed.</p>
  
  <pre><code>private static IConfiguration Configuration { get; set; }
  static void Main(string[] args)
  {
      ServiceCollection services = new ServiceCollection();
      ConfigureServices(services);
      var serviceProvider = services.BuildServiceProvider();
      var logger = serviceProvider.GetService&lt;ILoggerFactory&gt;()
          .CreateLogger&lt;Program&gt;()
      var service = serviceProvider.GetService&lt;TestClass&gt;();
      service.TimmerTriggerTask();
  }
  
  private static void ConfigureServices(IServiceCollection services)
  {
      IConfiguration config = new ConfigurationBuilder()
              .AddJsonFile("appsettings.json", true, true)
              .Build();
      services.AddApplicationInsightsTelemetry("8028437c-1111-2222-8293-2cf3f3f106a8"); //instrumentation key
      services.AddLogging(builder =&gt; builder.AddConsole());
  }
  
  TestClass.cs
  public class TestClass
  {
      private readonly ILogger&lt;TestClass&gt; _logger;
  
      public TestClass(ILogger&lt;TestClass&gt; logger)
      {
          Console.WriteLine("Ctor");
          _logger = logger;
      }
  
      public void TimmerTriggerTask()
      {
          Console.WriteLine("Timer");
      //LOG BELOW IN APPLICATION INSIGHTS
          _logger.LogTrace("Hello World");
          _logger.LogInformation(DateTime.Now.ToString());
      }
  }
  </code></pre>
  
  <p>I need to log all the information and exceptions in Application Insights. looking to integrate loggerfactory with applicationInsights.</p>
  
  <p>I am looking for something what we can do in .NET Core Web app</p>
  
  <pre><code>WebHost.CreateDefaultBuilder(args).UseApplicationInsights()
  loggerFactory.AddApplicationInsights(app.ApplicationServices, defaultLogLevel);
  </code></pre>
  
  <p>Please help me as how do i use logger classes to log into applicationinsights.</p>
  
  <p>Please provide an alternative solution if what i am doing is incorrect.</p>