title: DI with ILogger in Azure webJob
body: <p>I have an azure webjob project created in .net framework 4.6. i am trying to implement dependency injection with ILogger and log the information in application insights. </p>
  
  <pre><code>class Program
  {
      private static IConfigurationRoot configuration;
  
      // Please set the following connection strings in app.config for this WebJob to run:
      // AzureWebJobsDashboard and AzureWebJobsStorage
      public static void Main()
      {
          var config = new JobHostConfiguration();
  
          if (config.IsDevelopment)
          {
              config.UseDevelopmentSettings();
          }
          var builder = new ConfigurationBuilder()
                        .SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                        .AddEnvironmentVariables();
  
          IServiceCollection serviceCollection = new ServiceCollection();
          ConfigureServices(serviceCollection);
          //config.JobActivator = new CustomJobActivator(serviceCollection.BuildServiceProvider());
          config.LoggerFactory = new LoggerFactory()
             .AddApplicationInsights(configuration.GetSection("ApplicationInsights")["InstrumentationKey"], null);
          config.UseTimers();
          var host = new JobHost(config);
          // The following code ensures that the WebJob will be running continuously
          host.RunAndBlock();
      }
  
      private static void ConfigureServices(IServiceCollection serviceCollection)
      {
          serviceCollection.AddTransient&lt;Functions, Functions&gt;();
          serviceCollection.AddLogging();
      }
  }
  </code></pre>
  
  <p>appSettings.json</p>
  
  <pre><code>{   
      "ApplicationInsights": {
          "InstrumentationKey": "8028437c-888-666-444-2cf3777106a8"
      }
  }
  </code></pre>
  
  <p>Functions.cs</p>
  
  <pre><code>public class Functions
  {
      private readonly ILogger&lt;Functions&gt; _logger;
  
      public Functions(ILogger&lt;Functions&gt; logger)
      {
          _logger = logger;
      }
  
      public void ProcessTimerMessage([TimerTrigger("0 */5 * * * *")]TimerInfo timerInfo, TextWriter log)
      {
          //LOG THIS IN APP INSIGHTS
          _logger.LogError("Error");
      }
  }
  </code></pre>
  
  <p>I have also tried adding the below code in ConfigureServices method. But still no luck.</p>
  
  <pre><code>var telemetryClient = new TelemetryClient(new TelemetryConfiguration()
  {
         InstrumentationKey = "&lt;&lt; Instrumentation Key &gt;&gt;"
  });
  serviceCollection.AddSingleton(x =&gt; telemetryClient).AddLogging();
  </code></pre>
  
  <p>Only the trace logs gets logged in app insights whereas the logger object logs doesnot appear. 
  Please help</p>