title: Azure WebJob, ILogger DI Injected logging to BlobStorage
body: <p>I build my services mainly for my API therefore they all get an ILogger&lt;> injected in their contructor. (Azure WebApps)</p>
  
  <p>Now I am using a web job in Azure too and build it with DI following this instruction: <a href="https://matt-roberts.me/azure-webjobs-in-net-core-2-with-di-and-configuration/" rel="nofollow noreferrer">https://matt-roberts.me/azure-webjobs-in-net-core-2-with-di-and-configuration/</a></p>
  
  <p>My problem now is, that I want the service.logger instance to log into the Azure BlobStorage for the web jobs.
  Via binding I get an ILogger instance for the time triggered function. But how can I make the service log to the BobStorage?</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>loggerFactory.AddConsole();
  loggerFactory.AddAzureWebAppDiagnostics();
  
  public async Task TimeJob(
      [TimerTrigger("0 */5 * * * *", RunOnStartup = true)] TimerInfo timerInfo,
      ILogger log
      )
      ....
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>IServiceCollection services = new ServiceCollection()
  .AddLogging(config =&gt;
  {
      config.AddConfiguration(configuration.GetSection("Logging"));
      config.AddConsole();
      config.AddAzureWebAppDiagnostics();
   })
   .AddSingleton(configuration)
   ;
  
   // register services and such
   configurationCallback(services);
  
   return services.BuildServiceProvider();
  </code></pre>
  
  <p>.</p>
  
  <pre><code>        Program.Configuration = SetupHelper.SetupConfiguration(args);
          Program.Services = SetupHelper.SetupServiceProvider(Program.Configuration, Program.ConfigureServices);
          var loggerFactory = Program.Services.GetService&lt;ILoggerFactory&gt;();
  
          var hostConfig = new JobHostConfiguration(Program.Configuration)
          {
              JobActivator = new CustomJobActivator(Program.Services),
              LoggerFactory = loggerFactory
          };
          hostConfig.Queues.MaxPollingInterval = TimeSpan.FromSeconds(10);
          hostConfig.Queues.BatchSize = 1;
          hostConfig.UseTimers();
  
          //hostConfig.Tracing.ConsoleLevel = TraceLevel.Off;
  
          if (hostConfig.IsDevelopment)
          {
              hostConfig.UseDevelopmentSettings();
          }
  
          var host = new JobHost(hostConfig);
          host.RunAndBlock();
  </code></pre>
  
  <p>Sample Service</p>
  
  <pre><code>public abstract class Service : IService
  {
      protected readonly ILogger Logger;
      protected readonly IUserInfo UserInfo;
  protected bool Disposed;
  
  protected Service(
      ILogger logger,
      IUserInfo userInfo)
  {
      this.Logger = logger;
      this.UserInfo = userInfo;
  }
  
  public abstract void Dispose();
  </code></pre>