开发者

Dynamically change the log4net connection string

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">


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜