title: ASP.NET Core ILogger does not log to Trace unless a debugger is attached
body: <p>I am having a weird situation where I cannot receive any Trace from ASP.NET Core <code>ILogger&lt;T&gt;</code> unless a debugger is attached (even if I am running in Debug configuration). First let me explain:</p>
  
  <p>I need to write logs to files by date, and I previously wrote a simple custom TraceListener for that, so I think I can reuse it without writing new Log Provider:</p>
  
  <pre><code>    public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
          Host.CreateDefaultBuilder(args)
              .ConfigureLogging(logging =&gt;
              {
                  logging.AddTraceSource("IISLogCleaner");
                  // I added below line to make sure I am not missing anything
                  logging.SetMinimumLevel(LogLevel.Trace);
              })
              .ConfigureWebHostDefaults(webBuilder =&gt;
              {
                  webBuilder.UseStartup&lt;Startup&gt;();
              });
  </code></pre>
  
  <p>In <code>Startup.ConfigureServices()</code>, I add the listener:</p>
  
  <pre><code>            var listener = new DailyTraceListener(folder);
              Trace.Listeners.Add(listener);
  </code></pre>
  
  <p>Now for the logging background task:</p>
  
  <pre><code>    ILogger&lt;CleanupTask&gt; logger;
  
      public CleanupTask(ILogger&lt;CleanupTask&gt; logger)
      {
          this.logger = logger;
      }
  
      // ...
  
      async Task&lt;int&gt; WorkAsync(CancellationToken token)
      {
          System.Diagnostics.Debug.WriteLine("Start Working");
          this.logger.LogInformation("Start working");
  
          await Task.Delay(1000);
  
          this.logger.LogInformation("Work finished");
          return await Task.FromResult(10000);
      }
  </code></pre>
  
  <p>Here's the problem: with debugger attached, all the logs are written to log file. However, when I choose to Run without Debugging, even in Debug configuration, no file is created, no content is written, until I added the <code>Debug.WriteLine</code> calls, now only these lines get logged, but all the <code>logger.LogInformation()</code> are not recorded.</p>
  
  <p><a href="https://i.stack.imgur.com/qaLU7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qaLU7.png" alt="enter image description here"></a></p>
  
  <p>The Output window however, receive all the messages:</p>
  
  <p><a href="https://i.stack.imgur.com/CeDEU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CeDEU.png" alt="enter image description here"></a></p>
  
  <p>To be safe, I have deleted the <code>appsettings.Development.json</code> file and only <code>appsettings.json</code> remains. Here is the Log content:</p>
  
  <pre><code>"Logging": {
      "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information"
      }
  },
  </code></pre>