Roaming configuration for Logging Application Block

Topics: Logging Application Block
Nov 15, 2009 at 9:50 AM


I am using EL 4.1.

I need to define 2 configuration levels which will include the configurations for the logging. The roaming configuration needs to override the global configuration.

In the global configuration I have defined a trace listener named "Rolling Flat File Trace Listner". In the roaming configuration I have defined the same listener but with slight changes (in the rollInterval attribute).

On startup, I merge this 2 files and save it to the bin.

See the code:

/// Load the master configuration for the .exe from Resource\Config

var exeMap = new ExeConfigurationFileMap {ExeConfigFilename = "C:\Global\global.config")};
configuration = ConfigurationManager.OpenMappedExeConfiguration(exeMap, ConfigurationUserLevel.None);

/// Change the AllowExeDefinition for each section to MachineToRoamingUser
/// for enabling the merging with the configuration from ResourceLocal
foreach(ConfigurationSection section in configuration.Sections)
     if (section.SectionInformation.IsDeclared)
           section.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToRoamingUser;

/// Save the configuration file with the changes in configuration to the bin

/// Set the mapping for both the exe and roaming configuration
exeMap.ExeConfigFilename = "loggingtest.exe.config";
exeMap.RoamingUserConfigFilename = "C:\Roaming\roaminguser.config";

/// Load the merged configuration
configuration = ConfigurationManager.OpenMappedExeConfiguration(exeMap, ConfigurationUserLevel.PerUserRoaming);

var loggingConfiguration = configuration.Sections["loggingConfiguration"];

The exception I get is:

System.Configuration.ConfigurationErrorsException occurred
  Message="The entry 'Rolling Flat File Trace Listener' has already been added. (C:\\Documents and Settings\\liorc\\Desktop\\Samples\\Star\\ResourceLocal\\Config\\LogSettings.config line 5)"
  BareMessage="The entry 'Rolling Flat File Trace Listener' has already been added."
  Filename="C:\\Documents and Settings\\liorc\\Desktop\\Samples\\Star\\ResourceLocal\\Config\\LogSettings.config"
       at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
       at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
       at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
       at System.Configuration.ConfigurationSectionCollection.Get(String name)
       at System.Configuration.ConfigurationSectionCollection.get_Item(String name)
       at Star.Infrastructure.Configuration.ConfigManager..ctor() in C:\Documents and Settings\liorc\Desktop\Samples\Star\Infrastructure\Configuration\ConfigManager.cs:line 101

 Thanks for the help.




Nov 16, 2009 at 9:08 AM


Have you tried changing the name of the one Rolling Flat File Trace Listener? Say, the one from the Global, change the name to "Global Rolling Flat File Trace Listener".

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.