logo       

RE: Dynamically changing connection string in XML config file.: msg#00043

log.log4net.user

Subject: RE: Dynamically changing connection string in XML config file.

I've also done this in my project. This seems to work for me.

After calling Configure() and GetLogger() to return an ILog object
(called MyLogObject below), I put in this code to loop through all
appenders and set all connection strings to MyConnectionString.

foreach (log4net.Appender.IAppender logAppender in
((log4net.Repository.Hierarchy.Logger)MyLogObject.Logger).Appenders)
{
if (logAppender.GetType() ==
typeof(log4net.Appender.ADONetAppender))
{

((log4net.Appender.ADONetAppender)logAppender).ConnectionString =
MyConnectionString;

((log4net.Appender.ADONetAppender)logAppender).ActivateOptions();
}
}

Aaron Hart

-----Original Message-----
From: Josh Kewley [mailto:jkewley@xxxxxxxxxxx]
Sent: Friday, February 11, 2005 10:24 AM
To: Log4NET User
Subject: RE: Dynamically changing connection string in XML config file.

I did a similar thing in a web environment for a FileAppender.
http://insario.com/blog/jfk/archive/2004/11/30/164.aspx
-Josh

-----Original Message-----
From: Diego Barros [mailto:diego@xxxxxxxxxxx]
Sent: Thursday, February 10, 2005 9:04 PM
To: Log4NET User
Subject: Dynamically changing connection string in XML config file.

Hello all,

I was wondering whether it was possible to set the ADONetAppender's
connection
string in code when configuring log4net? During testing I have a config
file which had a hard coded connection string for the database
connection.
I would like to modify that just prior to log4net being configured, but
still have the configuration in the XML file. Is this possible?

Where I had:

log4net.Config.DOMConfigurator.Configure(new
System.IO.FileInfo(@"c:\temp\MyApp.conf"));

I would like to have a different connection string for the
ADONetAppender
than what exists in MyApp.conf. Is this possible? Or should I go about
this
another way? The connection string that I need to use may change and
would
be retrieved from another location.

Any help would be appreciated.

Cheers,
Diego





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise