title: How to log data in console/webjob output and on azure apps service with application insights
body: <p>I am using webjobs <strong>v3</strong> with HostBuilder.</p>
  
  <p>How do I have to configure the logger that I can use a telemetryClient to tracktrace data which is visible in the console output AND visible in the azure app service
  this webjob is running on?</p>
  
  <p>I would like to get a ILogger instance which logs to console AND azure.</p>
  
  <p>this line of code:</p>
  
  <pre><code> var logger = host.Services.GetRequiredService&lt;ILogger&lt;Program&gt;&gt;();
              logger.LogInformation("I log only in the console but not azure.");
  </code></pre>
  
  <p>DOES not send its data to azure application insights charts...</p>
  
  <p>I do NOT want to use the ILogger AND the telemetryclient to log stuff that would be stupid.</p>
  
  <pre><code>var builder = new HostBuilder()
                  .UseEnvironment("Development")
                  .ConfigureWebJobs(b =&gt;
                  {
                      // Add extensions and other WebJobs services
                  })
                  .ConfigureAppConfiguration(b =&gt;
                  {
  
                      // Add configuration sources          
                  })
                  .ConfigureLogging((context, b) =&gt;
                  {
                      // Add Logging Providers
                      b.AddConsole(); 
  
  
                      // If this key exists in any config, use it to enable App Insights
                      string appInsightsKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]; // taken from the appservice environmentvariable
  
                      appInsightsKey = "xxxxxxxx";
  
                      if (!string.IsNullOrEmpty(appInsightsKey))
                      {
                          // This uses the options callback to explicitly set the instrumentation key.
                          b.AddApplicationInsights(o =&gt; o.InstrumentationKey = appInsightsKey);
                      }
                  })
                  .UseConsoleLifetime();
  
              var host = builder.Build();
  
              // my code like telemetryClient.TrackTrace("show this text in console output AND azure app service where this webjob belongs to")
  
              using (host)
              {
                  host.Run();
              }
  </code></pre>