0

This might be a simple question. Is there any way by which we can set the databaseInstanceName in Database Trace Listener programitically ? As my application interacts with different databases(lets say in the connectionString tag i have 3 connection strings pointing to different DBs) so I have a requirement to log the exception in db but into respective databases. I am not supoosed to create a separate db for logging.

Is there a way ?

Bose_geek
  • 498
  • 5
  • 18

1 Answers1

0

Using the fluent API to configure Enterprise Library...

var configurationSourceBuilder = new ConfigurationSourceBuilder();

// do other configuration here

configurationSourceBuilder
    .ConfigureLogging()
        .LogToCategoryNamed("Category")
            .SendTo.Database("Database Trace Listener")
                .UseDatabase("DatabaseInstance");

// or here

var configurationSource = new DictionaryConfigurationSource();
configurationSourceBuilder.UpdateConfigurationWithReplace(configurationSource);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource);

If the reason you have three connection strings is that your program has to support running in three different environments (dev/test/production?), a better option might be to have a single connection string instead. Then deploy configuration files customized for each environment, so that the code is identical for all environments.

Tim B
  • 2,340
  • 15
  • 21
  • Hey @Tim B. I added .WithOptions.SetAsDefaultCategory() in the above code and it started working. Thanks a lot :-) – Bose_geek Jul 31 '13 at 06:32