Reg. Load And Watch Config File

Nov 11, 2009 at 1:20 PM
Edited Nov 11, 2009 at 1:40 PM
MyConfig.config: (<categorySources> Section)
<categorySources>
   <add switchValue="All" name="cat1">   
     <listeners>   
	<add name="Listener1" />   
    </listeners>   
   </add>  
</categorySources>

//C# .net Code block Starts 

  IConfigurationSource prtlConfigSrc=null;

LogWriterFactory factory =null; 
LogWriter writer = null;
prtlConfigSrc = new FileConfigurationSource("MyConf.config"); 
factory = new LogWriterFactory(prtlConfigSrc);	
writer = factory.Create();
//C# .net Code block Ends
I have created the LogWriter Object by using the code above ..
I want to modify the categorySource "cat1" switchValue in MyConf.Config when the application is in use.
I want to watch and reload the config file between some interval of time. Is it possible?
 
Thanks in advance!
 
Nov 12, 2009 at 2:47 AM

Here is a sample code for modifying the switchvalue:

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = "MyConfig.config";
Configuration entLibConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
LoggingSettings loggingSettings = (LoggingSettings)entLibConfig.GetSection(LoggingSettings.SectionName);

TraceSourceData general = loggingSettings.TraceSources.First(a => a.Name == "General");
general.DefaultLevel = SourceLevels.Error;

//Save the changes
entLibConfig.Save();

 

Detecting configuration changes: http://msdn.microsoft.com/en-us/library/dd203211.aspx

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 12, 2009 at 5:30 AM

Hi,

Thanks for you reply.

I am manually editing the MyConfig.Config when the application is in use. I dont want to update it using code.

Basically "cat1" switchValue is off (<add switchValue="Off" name="cat1">).  When exception raised, i am going to modify the "cat1" switchValue from Off to Verbose/All(<add switchValue="All" name="cat1">) manually(not using code). Then immediately i fire the action which raises exception to see the whole log.

Is there is any functionality like  Log4j's   org.apache.log4j.xml.DOMConfigurator.configureAndWatch(configFile, refreshInterval); 

I think you get my point.

Thanks in advance!

Nov 12, 2009 at 8:21 AM

I'm afraid there isn't something exactly like what you want.  The ConfigChangedEvent is what's available in enterprise library. 

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 12, 2009 at 9:40 AM

ok...

Where i can get Enterprise Library documentation(like MSDN).

Nov 12, 2009 at 10:17 AM
Edited Nov 12, 2009 at 10:19 AM

The documentation comes with the entlib installation package available in MSDN - http://msdn.microsoft.com/en-us/library/dd203099.aspx.

You can also choose to download the stand alone version - http://entlib.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=18859 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com