Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can use the connectionString of the current website for log4Net instead of configuring [duplicate]

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?

like image 458
Aiping He Avatar asked Mar 15 '12 15:03

Aiping He


People also ask

Where do you put ConnectionString?

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.

How do you read ConnectionString from configuration file into code behind?

To read the connection string into your code, use the ConfigurationManager class. string connStr = ConfigurationManager. ConnectionStrings["myConnectionString"].


1 Answers

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" /> ... 
like image 129
gustavodidomenico Avatar answered Oct 25 '22 11:10

gustavodidomenico