Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Reload app.config file without restarting app

Is there any way to reload the settings from an app config file without restarting the application? My app is a C# windows service, and I have implemented logging according to a level set in my app.config file. Normally the service just logs errors and warnings, but a setting in the app.config can be changed to tell the service to log debug and info messages as well. I don't have enough disk space to log all debug and info messages all the time.

I've had a good old hunt around for advice on this, and the best that's been offered is to develop a custom config file handler which implements a FileSystemWatcher to monitor the config file for changes. However, our code base is now large enough that changing our configuration management is going to be a monster job. I could just change the logging component to read it's log level from somewhere else, but then we have two locations for config information, which is not good either.

I can't believe the recommended config file management approach does not have any support for on-the-fly config changes. Am I missing something really simple?

Mark B
Friday, April 8, 2005

No, you're not missing anything. The default configuration system is indeed read once, cache forever, which is why you can't change the file.

If I might be so bold as to pimp my team's software, you could considering using the Configuration app block from Enterprise Library.

Brad Wilson [MSFT]
Friday, April 8, 2005

Log4Net has a "WatchConfigFile" option and is much simpler to configure and use than Enterprise Library.

Friday, April 8, 2005

Thanks for the suggestions guys. Due to the size of our code base and the fact that only one setting needs to be changed on the fly, I have left most config settings alone, and just changed the logging component so that it reads the setting from the same config file, then starts a FileSystemWatcher to re-read the setting if the config file changes.

I guess if we were just starting our application design, we would know now to use Log4Net or the Enterprise Library for our logging.

Mark B
Monday, April 11, 2005

*  Recent Topics

*  Fog Creek Home