Recently, I was working with a client who has just started with the adoption of cloud technologies and they have a long roadmap before they reach Kubernetes or a container-based development approach.
There were a few batch jobs that I was supposed to write, that would perform some push/pull from the existing LOBs to Azure. This was to minimize my efforts so that I don't have to maintain different configs for each region like DEV, QA, and PROD. I wrote a custom config section to be able to slice the different app settings based on the region. Here are some details and codes.

Custom Config Section Entry in the App.Config
  1. <configSections>
  2. <section name ="serverConfiguration" type ="ServerConfiguration.ServerSettingHandler, ServerConfiguration"/>
  3. </configSections>
  4. <serverConfiguration>
  5. <server name ="Dev">
  6. <settings>
  7. <add key ="ck" value ="ckDEV" />
  8. <add key ="abc" value ="mlDEV" />
  9. <add key ="cde" value ="p3DEV" />
  10. <add key ="efg" value ="oppDEV" />
  11. </settings>
  12. </server>
  13. <server name ="QA">
  14. <settings>
  15. <add key ="ck" value ="ckQA" />
  16. <add key ="abc" value ="mlQA" />
  17. <add key ="cde" value ="p3QA" />
  18. <add key ="efg" value ="oppQA" />
  19. </settings>
  20. </server>
  21. <server name ="PRD">
  22. <settings>
  23. <add key ="ck" value ="ckPRD" />
  24. <add key ="abc" value ="mlPRD" />
  25. <add key ="cde" value ="p3PRD" />
  26. <add key ="efg" value ="oppPRD" />
  27. </settings>
  28. </server>
  29. </serverConfiguration>
Fetch the Specific Setting Value
  1. var server = ServerConfigManager.GetServerSetting("dev","ck");
  2. Console.WriteLine(server);
  3. // Prints
  4. // ckDEV
Fetch the All Setting Value
  1. var server = ServerConfigManager.GetServer("Dev");
  2. foreach (KeyValuePair<string, string> setting in server?.Settings)
  3. {
  4. Console.WriteLine($"Key : {setting.Key} Value : {setting.Value}");
  5. }
  6. // Prints
  7. /*
  8. Key : ck Value : ckDEV
  9. Key : abc Value : mlDEV
  10. Key : cde Value : p3DEV
  11. Key : efg Value : oppDEV
  12. */
Other Wrappers

If you decide to name the server with the Machine name, then you can also make use of the below method for fetching the details.
  1. // The GetCurrentServer uses the Environment.MachineName to look in the Config sections and Fetches the value.
  2. var server = ServerConfigManager.GetCurrentServer()
Attached code has all the source files.
I know this has been available in C# for almost a decade or so, but this blog may be a good read to refresh your knowledge on this old technique.