KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am developing an application in C# under Framework 4.0. In my application I would like to create separate configuration file that is not the app.config file. The configuration file contains custom configuration sections we developed for the product. I don't want to reference this file from the app.config using the configSource. I want to load it at runtime and read it's content. An example to what I mean is the log4net that allow you to write the configuration in the log4net.config file. Can anyone help how to do that without writing code that mimcs the code that exists in the framework ? UPDATE: based on the answer from Kaido I wrote utility class that reads custom configuration file and has the ability to refresh the Config content when the file on the file system changes. The usage in this class is as follows: Get the configuration file content // Create configuration reader that reads the files once var configFileReader = new CustomConfigurationFileReader("c:\\myconfig.config"); var config = configFileReader.Config; // Do any action you want with the config object like: config.GetSection("my.custom.section"); // or, var someVal = config.AppSettings.Settings["someKey"]; Get notifications when the configuration file changes // Create configuration reader that notifies when the configuraiton file changes var configFileReader = new CustomConfigurationFileReader("c:\\myconfig.config", true); // Register to the FileChanged event configFileReader.FileChanged += MyEventHandler; ... private void MyEventHanler(object sender, EventArgs e) { // You can safely access the Config property here, it is already contains the new content } In the code I used PostSharp in order to validate the constructor input parameter to verify that the log file is not null and that
Tags (comma-separated)
Save Edits
Cancel