Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change the log4net connection string

Tags:

c#

.net

log4net

I'm new to log4net and was given a task to Switch the way log4net gets the connectionstring.

The connectionstring may be different for different groups of people who visits the site. i.e. company A has users who use the site and has its own db and therefore has its own logging table which log4net uses.

We were currently using a connection string in a webconfig file.

I created this code but doesn't work

MyNamspace
{
     public class Log4NetAdoNetAppender :log4net.Appender.AdoNetAppender
     {
          public new string ConnectionString
          {
                get { return base.ConnectionString; }
                set
                {                
                    base.ConnectionString = Service.GetConnectionString();
                }
          }
     }
}

<appender name="ADONetAppender" type="MyNamspace.Log4NetAdoNetAppender">
like image 862
David Avatar asked Apr 22 '26 14:04

David


1 Answers

I think you could:

  • Configure log4net by code instead of by xml
  • configure as many loggers and appenders as "connection strings"
  • use the right logger to log based on the user

Hope it helps

like image 123
Ivo Avatar answered Apr 25 '26 03:04

Ivo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!