logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: Log4Net Appender
Date Sat, 14 Jun 2008 15:37:21 GMT
By "each class that is loaded" do you mean each instance of the class needs to write to its
own company database?

 CompanyService companyService = new CompanyService("AlphaCompany");
 CompanyService companyService = new CompanyService("BetaCompany");
 CompanyService companyService = new CompanyService("GammaCompany");

If that's the case you could extend ILog and add methods that accept an identifer which would
be used as the database table:

public class CompanyService
  private readonly static DatabaseLog log = new DatabaseLog(LogManager.GetLogger(typeof(CompanyService)));

  private string companyName;

  public CompanyService(string companyName)
   this.companyName = companyName;

  private int CalculateSomething()
   log.Debug(companyName, "Starting to calculate something");

And/or you could create a custom AdoNetAppender that looks for a special MDC value and understands
what database table to map that to:

<appender name="CompanyAdoNetAppender">
   <companyToTable company="AlphaCompany" table="Alpha" />
   <companyToTable company="BetaCompany" table="Beta" />

----- Original Message ----
From: Scott Carr <scarr@progbits.com>
To: log4net-dev@logging.apache.org
Sent: Wednesday, June 4, 2008 1:14:26 PM
Subject: Log4Net Appender

I am using a static logger at the top of my class, and it is working fine.

Now I need to create an Appender that goes to a specific Company db.  
This changes for each class that is loaded, though.  Is there a way to 
use the static logger in this fashion, where I can change the specific 
instance for the Class Logger?

What would be the best way to implement this?

Should this go on the users list instead? 


View raw message