Hi,
I have a logging class that I use in all my classes. The code for the logger was originally used like so:
Properties.Settings s = new Properties.Settings();
String path = s.logPath;
the app.config file looks likes this: (also every project that uses the Logger must have this AppSettingsSection in the App.config)
however this caused a problem in the following situation. A class that usses the Logger class is also being used by a COM object. For some reason, the COM object uses some funky .Config file. To remedy this I changed the way I retrieve the app settings as follows:
Configuration cs = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ClientSettingsSection settingsSection = ((ClientSettingsSection)(cs.SectionGroups["applicationSettings"].Sections["G2G.Logging.Properties.Settings"]));
SettingElementCollection settings = settingsSection.Settings;
String path = settings.Get("logPath").Value.ValueXml.InnerText;
This works beautifully but it is very ugly in my opinion. Does anyone have any suggestions of a more pretty way to do this?
Bechir BejaouiPosted Dec 27, 2008, 7:31 PM
http://www.c-sharpcorner.com/UploadFile/yougerthen/404082008080449AM/4.aspx
you can also use the Visual studio IDE to add the configuration section and retrive them
http://www.c-sharpcorner.com/UploadFile/yougerthen/104082008062120AM/1.aspx