This sample demonstrates how to read the revision history of a Configuration Setting in a Configuration Store. To do this, we create a setting, change it twice to create revisions, then read the revision history for that setting using a SettingSelector
that uniquely identifies the configuration setting by its key name. The sample uses a configuration setting with a timestamp in the key name to ensure the setting hasn't been used before and thereby minimize the size of the revision history.
To get started, you'll need a connection string to the Azure App Configuration. See the README for links and instructions.
To interact with Azure App Configuration, you need to instantiate a ConfigurationClient
. You can use either an endpoint URL and a TokenCredential
or a connection string.
For the sample below, you can set connectionString
in an environment variable, a configuration setting, or any way that works for your application. The connection string is available from the App Configuration Access Keys view in the Azure Portal.
var client = new ConfigurationClient(connectionString);
First, create an initial ConfigurationSetting
instance and set it in the Configuration Store.
ConfigurationSetting setting = new ConfigurationSetting($"setting_with_revisions-{DateTime.Now:s}", "v1");
await client.SetConfigurationSettingAsync(setting);
Every time SetConfigurationSettingAsync
succeeds, a new revision is created.
setting.Value = "v2";
await client.SetConfigurationSettingAsync(setting);
setting.Value = "v3";
await client.SetConfigurationSettingAsync(setting);
To asynchronously get all unexpired revisions, call GetRevisionsAsync
with a setting selector that has KeyFilter
equal to settings.Key
. This will retrieve all revisions of this setting in the store. See App Configuration REST API for more information about filtering.
var selector = new SettingSelector { KeyFilter = setting.Key };
Debug.WriteLine("Revisions of the setting: ");
await foreach (ConfigurationSetting settingVersion in client.GetRevisionsAsync(selector))
{
Console.WriteLine($"Setting was {settingVersion} at {settingVersion.LastModified}.");
}
Revisions expire automatically and are available even after setting is deleted.
await client.DeleteConfigurationSettingAsync(setting.Key, setting.Label);
await foreach (ConfigurationSetting settingVersion in client.GetRevisionsAsync(selector))
{
Console.WriteLine($"Setting was {settingVersion} at {settingVersion.LastModified}.");
}