By default, each process will use its own configuration file. If you want the console application to have a configuration file, you need to add it to your project. After adding App.config to your project, whenever your project is created, App.config will be copied to the output folder as <application> .exe.config, where <application> is your application name (e.g. ConsoleApplication1.exe.config ) (Web.config is more complicated.)
Typically, configuration is added to this application configuration file.
Thus, the easiest way to configure the library assembly is to add its specific configuration to the configuration file of the hosting application.
Now it can be a little ugly. One way to make it less ugly is to have an application configuration file that simply references your configuration file using the ConfigSource attribute. Thus, you can expand your assembly with your configuration file and just have a hosting application add a few lines to your configuration file to reference your config. First they must add a link to configSections:
<configSections> <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </configSections>
Then they need to add a link to your configuration file:
<loggingConfiguration configSource="MyLoggingConfig.xml"/>
Now, perhaps you donβt want the users of your assembly to even know that there is a configuration file. If so, you can create your own stand-alone configuration file and open it using ConfigurationManager.OpenMappedExeConfiguration . Here is another example on how to use OpenMappedExeConfiguration.
source share