Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: ADO.Net Appender connection troubles
Prev Next
You are not authorized to post a reply.

Author Messages
Szymon Rozga

01/30/2008 3:39 AM  

I am trying to use the AdoNetAppender, but I am in an environment in
which the connection string is dynamic, depending on which of a series
of servers the app connects to. My idea is to get a reference to the
appender and reset the ConnectionString when my app knows which server
I am connecting to.

This sounds fine, but I only have access to an instance of an
IDbConnection. The ConnectionString property on that class returns the
connection string without the password, not surprisingly. This means
that when I set the ConnectionString property on the Appender and it
attempts to reconnect on error, it complains that I did not provide a
password.

Is it possible to set up the appender to somehow use a IDbConnection
instance instead of specifying the connection type and a connection
string and having log4net open another connection?

I have tried creating a subclass of AdoNetAppender exposing the
Connection property (so I am able to set the connection itself), but
that doesn't really fix it since it seems some internal state is being
held by AdoNetAppender. Allowing the class to reconnect on failure
tries to use the connection string, which doesn't really help.

Any ideas?

-Szymon

Ron Grabowski

01/30/2008 6:11 AM  

The current implementation doesn't allow a sub-class to easily provide its own IDbConnection. You'll have to copy and paste the contents of AdoNetAppender and modify the code to fit your needs.

AdoNetAppender needs a little refactoring so things like this are possible.

Ron Grabowski

01/31/2008 6:53 AM  

I made a CreateConnection method that's implemented like this:

 virtual protected IDbConnection CreateConnection(Type connectionType, string connectionString)
 {
  IDbConnection connection = (IDbConnection)Activator.CreateInstance(connectionType);
  connection.ConnectionString = connectionString;
  return connection;
 }

Eventually you'll be able to override that method to create your own connection object. CreateConnection fits into the re-initialize process when a reconnect is required.

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > ADO.Net Appender connection troubles



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement