Logging to database, connection in external config files

Topics: Logging Application Block
Jan 14, 2009 at 5:53 PM
I am using the Logging AB to log exceptions to the database for my web app.
The web app has a web.config file for some common app settings and then several external configuration files that contain different settings and connection strings.

I load up a different config object based on a query string parameter that comes in as follows:

   string divID = ConfigurationKeys.DIV_PREFIX + Request.QueryString[QueryStringParameters.DIVISION_ID];

  string externalConfigFileName = ConfigurationManager.AppSettings[divID];

  string path = Server.MapPath(@"~/DivisionSpecificConfig/" + externalConfigFileName);
  Configuration config = ConfigurationManager.OpenExeConfiguration(path);

So, I am wondering how to get the Logger to use the logging configuration settings that are in the external config file when logging exceptions?

Thanks
Cory

Jan 15, 2009 at 1:00 AM
You would create a LogWriterFactory that will accept an IConfigurationSource.  In your case, your IConfigurationSource would be an instance of FileConfigurationSource;

IConfigurationSource source = new FileConfigurationSource(path);
LogWriterFactory factory = new LogWriterFactory(source);
LogWriter writer = factory.Create();


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Jan 15, 2009 at 3:38 PM
Thank you Sarah,
It worked like a charm!

Cory