So I have been poking around both here on SO and google for the last few days for information about app.config
.
I am writing a program that will need to generate SQL scripts using values entered by a user. Originally I was using app.config
to store some default values to load into the program when it is first started up. This worked fine until I tried to store the new values back into the app.config
file. This is when I found that app.config
is read only and I should have been using user.config
.
I have several questions that I can't seem to find the answers to:
Is it recommended to use
settings.Setting
to declare all the values that I want to useapp.config
? Or is entering them in by hand is enough?I keep reading about how
user.config
overridesapp.config
settings. But when I update myuser.config
file, the program still reads from the originalapp.config
file
This is from my wrapper class
public NameValueCollection ReadSettings(string sectionName)
{
NameValueCollection scripts = null;
try
{
//read in the current values from the section
scripts = (NameValueCollection)ConfigurationManager.GetSection(sectionName);
if (scripts == null) throw new appConfigException(String.Format("The section {0} does not exists in app.config", sectionName));
}catch (Exception e){
//print out the log file
StreamWriter writer = new StreamWriter(DateTime.Now.ToString("d-MMM-yyyy") + "log.txt");
writer.WriteLine(e.ToString());
writer.Close();
//kill the application process so the user cannot advance further
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
return scripts;
}
is the ConfigurationManager
supposed to automatically know to start reading from the user.config
? Or do I need to change this section of code to reflect that?