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.
| 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. |
|
|
|
ActiveForums 3.7
|