How to find out what appsettings changes in C #?

Is there a way (an event would be a better option) that will notice my code that changed the application settings?

Exactly I'm trying to implement a Windows service in which the administrator has to change the online behavior without restarting the service.

I was thinking about FileSystemWatcher , but in this option I will have to hard-code the path and name in the configuration file, so maybe there is another way to do this?

UPDATE

Below are the answers to using AppDomain.CurrentDomain.SetupInformation.ConfigurationFile , but this option will not work if I have an external configuration file like this:

 <configuration> <appSettings configSource="appsettings.config"/> </configuration> 
+3
source share
2 answers

You can use FileSystemWatcher with the path from this statement:

 AppDomain.CurrentDomain.SetupInformation.ConfigurationFile 

No hard coded paths required.

+2
source

possibly using a timer in the background thread and checking the checksum of the configuration file every 5 seconds. If changed, than fire configuration change event.

0
source

Source: https://habr.com/ru/post/1496869/


All Articles