title: Log configuration changes in ASP.NET Core
body: <p>I want to log when configuration is changed.</p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/primitives/change-tokens" rel="nofollow noreferrer">I do this</a> in <code>Program.cs</code> or <code>Startup.cs</code>:</p>
  
  <pre><code>ChangeToken.OnChange(
    () =&gt; configuration.GetReloadToken(),
    state =&gt; logger.Information("Configuration reloaded"),
    (object)null
  );
  </code></pre>
  
  <p>But I get double change reports, so it needs to be debounced. <a href="https://github.com/aspnet/FileSystem/issues/287" rel="nofollow noreferrer">The advice is to do this</a>:</p>
  
  <pre><code>ChangeToken.OnChange(
    () =&gt; configuration.GetReloadToken(),
    state =&gt; { Thread.Sleep(2000); logger.Information("Configuration reloaded"); },
    (object)null
  );
  </code></pre>
  
  <p>I'm using <code>2000</code> here as I'm not sure what's a reasonable value.</p>
  
  <p>I've found that sometimes I still get multiple change detections, separated by 2000 milliseconds. So the debounce doesn't work for me, just causes a delay between reported changes. If I set a high value then I only get one report, but that isn't ideal (and conceals the problem).</p>
  
  <p>So I'd like to know:</p>
  
  <ul>
  <li><strong>Is this really debouncing, or just queueing reported changes?</strong></li>
  <li>I've used values from 1000 to 5000 to varying success. What are others using?</li>
  <li>Is the sleep issued to the server's main thread? I hope not!</li>
  </ul>