How to share an app.config between several applications

  • Thread starter Thread starter ThomasD
  • Start date Start date
T

ThomasD

I am using TraceSource to log errors and such. I have a custom
tracelistener I use for this, and this is setup in the app.config like
this:

<system.diagnostics>
<trace autoflush="true"/>

<sources>
<source switchValue="All" name="Application" >
<listeners>
<add name="LogFile"></add>
</listeners>
</source>
</sources>

<sharedListeners>
<add name="LogFile" initializeData="AppLog;5000"
type="FileTraceListener, MyTools"></add>
</sharedListeners>
</system.diagnostics>

Now, using this technique I will actually need an app.config for each
and every assembly in the project. Which I really want to.

How do I share this app.config between all assemblies? It is so very
easy to change the trace configuration by simply editing this
app.config, instead of doing it through code.

I have been looking at ConfigurationManager, which lead me nowhere,
and AppDomain.SetupInformation, which is only useful when creating NEW
application domains.

So, is there any way to share an app.config file between several
assemblies, without resorting to XmlDocument and lots of coding.
 
I am using TraceSource to log errors and such. I have a custom
tracelistener I use for this, and this is setup in the app.config like
this:

<system.diagnostics>
<trace autoflush="true"/>

<sources>
<source switchValue="All" name="Application" >
<listeners>
<add name="LogFile"></add>
</listeners>
</source>
</sources>

<sharedListeners>
<add name="LogFile" initializeData="AppLog;5000"
type="FileTraceListener, MyTools"></add>
</sharedListeners>
</system.diagnostics>

Now, using this technique I will actually need an app.config for each
and every assembly in the project. Which I really want to.

How do I share this app.config between all assemblies? It is so very
easy to change the trace configuration by simply editing this
app.config, instead of doing it through code.

I have been looking at ConfigurationManager, which lead me nowhere,
and AppDomain.SetupInformation, which is only useful when creating NEW
application domains.

So, is there any way to share an app.config file between several
assemblies, without resorting to XmlDocument and lots of coding.

Nevermind, I found it here:

http://aaronfeng.blogspot.com/2006/03/override-default-net-configuration.html

Basically all you gotta do, is BEFORE using anything from the config
file, run this line:

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configFile);

Where configFile is the path to the actual config file you want to
use.
 
Back
Top