Formatted Database Trace Listener always requires connection string with providerName

Topics: General discussion, Logging Application Block
Jul 31, 2011 at 7:24 AM
Edited Jul 31, 2011 at 7:26 AM

Hi ,

I am trying to wrap all Enterprise Logging application block configuration using Fluent API inside my C# code. Now I am able to create all trace Listener except Database Listener because it requires a connection string of the Database with the providerName. If I am supplying only connection string ,I am not able to create the LogWriter. following code snippet..are what I am doing in code.

SendTo

.Database ("Formatted Database TraceListener")

    .UseDatabase("Data Source=.\SQLExpress;Initial Catalog=Logging;Integrated ecurity=True;") ---> This is the connection string without Provider Name .

.FormatWith(new FormatterBuilder () .TextFormatterNamed("TextFormat"))

.WithWriteLogStoredProcedure ("WriteLog")

.WithAddCategoryStoredProcedure ("AddCategory");

However ,when I am using Connection string config with provider name  like below is working.

<connectionStrings>

   <add name="myConnString" connectionString="Data Source=.\SQLExpress;Initial Catalog=Logging;Integrated Security=True;roviderName="System.Data.SqlClient"/>  

 </connectionStrings>

 And use my database connection string for Database trace listioner like 

 .UseDatabase("myConnString") ---> This is the connection string I have created above with ProviderName which works

Now my requirement was to create this database listioner which should not depend upon any configuration inside caller app.config..

Can somebody help here

Thanks-Bikash

 

 

 

 

 

 

 


Aug 1, 2011 at 9:51 AM
Edited Aug 1, 2011 at 9:51 AM

Hi,

You also need to configure the database settings through configuration api. Here is a sample code:

builder.ConfigureData()
       .ForDatabaseNamed("MyDatabase")
         .ThatIs.ASqlDatabase()
         .WithConnectionString("server=(local); database=Northwind; Integrated Security=true;")
         .AsDefault();

In the UseDatabase, you should specify the instance name (not the connectionstring) where your data settings is defined:

SendTo.Database ("Formatted Database TraceListener") .UseDatabase("MyDatabase").

Hope this helps.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

 

 

Aug 1, 2011 at 1:59 PM

Thanks Noel for your response.

The problem with this approach,  when we update the databaseConfiguration setting using 

var configureSource=new DictionaryConfiguration()

//The configuration will be here

builder.UpdateConfigurationWithReplace(configureSource) -- > This will ovverride all dataConfiguration elements which are there in client (caller) config..which I dont want,,

var configSource = new DictionaryConfigurationSource();

 

 

Aug 2, 2011 at 3:03 AM

My apologies but I'm confused with your requirements. Is that right that you have already a dataConfiguration within your configuration and you don't want to override it with the database settings built from the fluent config api? I thought you are building all your config from the config api. Anyway, while it is true that it will override the dataConfiguration, you still have an option to get your settings from the configuration. Instantiating a database object from the Entlib container will do the trick:

Database myDatabase = EnterpriseLibraryContainer.Current.GetInstance<Database>();

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 2, 2011 at 10:37 AM

Sorry Noel for the confusion. Let me brief you on my requirement.

My requirement was below

> All configuration for Logging application block through code using Fluent  and without using Entlib Logging configuration in .config file.Caller will no need to set anything for logging.

> For Database Trace Listner ,we can only create the LogWriter object using out of two

  1.  Create <dataConfiguration> using code or in .config and then link that with UseDatabase property inside logging configuration code. This option is not possible because I dont want to override the caller Data Configuration.
  2.  Create <connectionString> sections either through code or .config and link that with UseDatabase . This is one possible solution which I am going to implement whereby I will create <connectionString> ,and save that in .config file at runtime. And then link the <connectionString name=""> name attribute with UseDatabase.

So I met my requirement but this is not the good solution . Without using these two options I sould be able to create Database Trace listners with below code..

SendTo
.Database ("Formatted Database TraceListener")
    .UseDatabase("Data Source=.\SQLExpress;Initial Catalog=Logging;Integrated Security=True;") - connection string without providerName.
.FormatWith(new FormatterBuilder () .TextFormatterNamed("TextFormat"))
.WithWriteLogStoredProcedure ("WriteLog")
.WithAddCategoryStoredProcedure ("AddCategory");

What I was expecting from the object model/API is that there should be one single API without any link with other config..if it is available now..I will be happy to use that.

Thanks-Bikash

Aug 3, 2011 at 6:46 AM

I see. Unfortunately, this is not currently supported. The Fluent API requires you to also configure the database settings that will be used by your logging. You can however log it here as a feature request.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 3, 2011 at 3:35 PM

Thanks ! I have logged feature request # 31159