diff --git a/Source/VaultSharp.Extensions.Configuration/VaultChangeWatcher.cs b/Source/VaultSharp.Extensions.Configuration/VaultChangeWatcher.cs index 657a360..d6ab993 100644 --- a/Source/VaultSharp.Extensions.Configuration/VaultChangeWatcher.cs +++ b/Source/VaultSharp.Extensions.Configuration/VaultChangeWatcher.cs @@ -32,7 +32,7 @@ public VaultChangeWatcher(IConfiguration configuration, ILogger? logger = null) } this._logger = logger; - + this._configProviders = configurationRoot.Providers.OfType().Where(p => p.ConfigurationSource.Options.ReloadOnChange).ToList() !; } @@ -54,26 +54,34 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) while (!stoppingToken.IsCancellationRequested) { - await Task.Delay(TimeSpan.FromSeconds(minTime), stoppingToken).ConfigureAwait(false); - if (stoppingToken.IsCancellationRequested) - { - break; - } - - for (var j = 0; j < this._configProviders.Count(); j++) + try { - var timer = timers[j]; - timer -= minTime; - if (timer <= 0) + await Task.Delay(TimeSpan.FromSeconds(minTime), stoppingToken).ConfigureAwait(false); + if (stoppingToken.IsCancellationRequested) { - this._configProviders.ElementAt(j).Load(); - timers[j] = this._configProviders.ElementAt(j).ConfigurationSource.Options.ReloadCheckIntervalSeconds; + break; } - else + + for (var j = 0; j < this._configProviders.Count(); j++) { - timers[j] = timer; + var timer = timers[j]; + timer -= minTime; + if (timer <= 0) + { + this._configProviders.ElementAt(j).Load(); + timers[j] = this._configProviders.ElementAt(j).ConfigurationSource.Options + .ReloadCheckIntervalSeconds; + } + else + { + timers[j] = timer; + } } } + catch (Exception ex) + { + this._logger?.LogError(ex, $"An exception occurred in {nameof(VaultChangeWatcher)}"); + } } } }