On stackoverflow are a couple of questions regarding how the get app.config values from code or using windows path variables.
- But I would like to know if i can use an already defined key inside the app.config xml file?
- The purpose is to avoid entereing the connection string many times.
Below you can see my connection string 'con_str':
<appSettings>
<add key="con_str" value="myDatabaseConnectionString"/>
</appSettings>
....
<log4net>
<appender name="AdoNetExceptionAppender"
type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<threshold value="FATAL"/>
<connectionType ... />
<connectionString
value= .... <--- How to use value from 'con_str' above?
/>
<commandText ... />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
</appender>
</log4net>
Is there a way to read the value of the key con_str
from the appSettings
node within app.config?
Update 1 after comment from user chadiusvt
I changed my app.config like this:
<appSettings>
<add key="con_strOrig" value="foo" />
</appSettings>
<connectionStrings>
<add name="connStr" connectionString="foo" />
</connectionStrings>
...
<log4net>
<appender name="AdoNetExceptionAppender"
type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<threshold value="FATAL"/>
<connectionType ... />
<connectionString value="connStr" />
...
As you can see with the last update it is possible to reference the connectionStrings
. But since in my code i always use appSettings i would have to change my code in many places.
Is there a way to let the <appSettings>
point to the connStr
key from the node <connectionsStrings>
?
Update 2 to adress the answer
I believe you misunderstood. I am looking for a way to reference another var inside the xml-file.