Alex Rivera | Logout

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

Asked 2012-03-15T15:36:37.220
29

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?

Edit
Report

1 Answer

1

You could do this by writing a custom ADO.NET appender and overriding the connection string:

public new string ConnectionString {
    get { 
        return base.ConnectionString; 
    }

    //you could set your own connection string here
    set { 
        base.ConnectionString = ConfigurationManager.ConnectionStrings ["Sql"].
            ConnectionString; 
    }
}

You could visit http://technico.qnownow.com/2012/03/12/how-to-write-custom-ado-net-appender-for-log4net/ for a complete example

answered 2012-03-19T18:31:57.630

Your Answer