Allowing a Windows Service to be configured

.net, c#, windows-services

Solution

you do as you expect. You use the app.config, which will be renamed to `<exeName>.config`when the project is built and then `<exeName>.config` will be read by the service called `<exeName>`.

Settings are applied in a layered way and may come from other configuration files on the machine, such as machine.config. You can read about how configuration is handled on MSDN

EDIT

In response to comment: A service will only read the config when it starts (for perf reasons). If you want to reload the config file later, you need to handle that yourself I think.

You could read the last modified date/time of the config file to determine if the file has been changed, or setup a file system watcher and then tell the configuration manager to reload that section again next time it is read, by calling `ConfigurationManager.RefreshSection("appSettings")` and that section will be reloaded from disk when you next access it. See the ConfigurationManager MSDN docs

Problem

I have a Windows Service that I'm creating and I'm wondering what options are available in order for me let developers configure the service. The service is part of an over all larger open source project and hence the service is going to be installed on lots of different machines. Normal I would use a web/app.config for this but I'm not sure if this is possible. Hence I am looking to so how others handle this case.

Original source