I use log4Net for my system's log. The connectionString node is mandatory if the appender type is the AdoNetAppender in Log4Net. However, I already have a connectionString in my website where I use Log4Net.
How can I use the connStr of the website for log4Net instead of configuring the same connstr again in the log4net config file?
Connection strings can be stored as key/value pairs in the connectionStrings section of the configuration element of an application configuration file. Child elements include add, clear, and remove.
To read the connection string into your code, use the ConfigurationManager class. string connStr = ConfigurationManager. ConnectionStrings["myConnectionString"].
It's quite simple, you just need to replace the appender connectionString
configuration.
In place of the connection string:
<connectionString value="[Complete Connection]" />
You just use the connectionStringName
configuration:
<connectionStringName value="ApplicationConnection" />
And then you have your application connection string:
<connectionStrings> <add name="ApplicationConnection" connectionString="Connection" providerName="System.Data.OracleClient" /> </connectionStrings>
Unfortunately you must have the connectionType
with the connectionStringName, example:
<appender name="AdoNetAppender_Oracle" type="log4net.Appender.AdoNetAppender"> <connectionType value="System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <connectionStringName value="ApplicationConnection" /> ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With