views:

11

answers:

0

In my app.config in a C# 3.5 app, I have this section:

<appSettings>
      <add key="deleteOldFiles" value="false"/>
          <! -- 25 other keys/values omitted -->
      <add key="deleteOldFiles" value="true"/>    
</appSettings>

At initial app rollout, the system did not delete files because the first server engineer made the config setting. Months later another server engineer didn't see the first value and added his own setting and one day we noticed a lot of files were deleted "by accident".

It looks like ConfigurationManager.AppSettings["deleteOldFiles"] just takes the last value and uses it. I need to add some defensive coding here... Does anyone have any recommendations on ensuring appSettings are only in the file once? I was thinking of putting them all in a Dictionary of some sort but really want to keep any additional lines of code low.

Thanks.

--- Update ---

This is going to be harder than I thought. I started to write some code and noticed that this:

var appSettings = ConfigurationManager.AppSettings.AllKeys;

only shows a single value. That means ConfigurationManager is doing its own "distinct work" on its own and just giving me the latest value. Hmmm...