I use the following method to update appSettings in the config file:
void UpdateSetting(string key, string value)
{
Configuration configuration = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
configuration.AppSettings.Settings[key].Value = value;
configuration.Save(ConfigurationSaveMode.Minimal);
ConfigurationManager.RefreshSection("appSettings");
}
But the saving sometimes breaks long lines (>80 chars).
For example, before saving:
<appSettings>
<add key="A very long configuration parameter for example1" value="true" />
<add key="A very long configuration parameter for example-2" value="true" />
<add key="A very long configuration parameter for example3" value="Long value" />
</appSettings>
After saving:
<appSettings>
<add key="A very long configuration parameter for example1" value="true" />
<add key="A very long configuration parameter for example-2"
value="true" />
<add key="A very long configuration parameter for example3" value="Long value" />
</appSettings>
Example #2 exceeds 80 chars and is split into 2 lines.
Example #3 is also >80 chars, but is not split.
Why is it and how to avoid the split?
Edit:
According to the links in the first comments, I understand I can't avoid the split when using ConfigurationManager
.
But I'd like to understand the logic/rules - Why my example #3 isn't split although the whole line is longer than example #2 ? Does it depend on the first parameter ("key") only?