views:

449

answers:

2

Hey all. This is my first StackOverflow question.

I'm already have a db connection string in my web.config file. I scanned the log4net docs, but can't seem to find a way to use it within the log4net section of my web.config file. Is is possible to do something like this?

<connectionStrings>
    <add name="connStr" connectionString="Data Source=localhost; ..." />
</connectionStrings>

<log4net>
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
    <connectionString connectionStringName="connStr"/>
      ...
</log4net>

Thanks!

+5  A: 

Create a class that extends AdoNetAppender - say, WebAppAdoNetAppender. Implement the ConnectionString property in that class, and retrieve the connection string from your web.config file in that property setter.

<log4net>
    <appender name="AdoNetAppender" type="MyApp.WebAppAdoNetAppender">
    ...

...

public class WebAppAdoNetAppender : log4net.Appender.AdoNetAppender
{
    public new string ConnectionString
    {
        get { return base.ConnectionString; }
        set { base.ConnectionString = ...   }
    }
}
Michael Petrotta
Stefan Egli's link indicates that a parameter doesn't yet exist. For the time being, this seems like the best way to go about it. Thanks Mr. Petrotta!
A: 

fyi this will be implemented in 1.2.11 according to this. however I have no idea when they are going to release it.

Stefan Egli
sounds like the feature I want is forthcoming