This article walks through the 'Enterprise Library: Logging application' configuration process to log data to database using WCF service.
Note that regardless of Web service type i.e., SOAP or RESTful the configuration process is same.
Visual Studio 2010 with .NET 4.0
Enterprise library 5.0
ASP.NET Web application on Client end.
Open Service Web.config using Enterprise library configuration tool
Open the Service Web configuration file using Enterprise library configuration tool, which can be found at C:\Program Files\Microsoft Enterprise Library 5.0\Bin [assuming that you chosen C: drive for Enterprise library installation process]
[Image: Enterprise library configuration tool location]
Note: Make sure that Service Web.config contains database connection string in connectionStrings section.
Step 1: Open Enterprise library configuration tool
Below screenshot shows the configuration tool after opening the service web.config file.
Step 2: _Choosing the Default database instance with in Database settings section
Choose the Default Database Instance from drop down list, in this example Logging is chosen as default one as shown below.
[Default Database Instance]
Step 3: Add Logging block block
Choose 'Logging Settings' to add logging application block from Blocks menu as shown below screenshot.
Step 4: Expand Logging Settings section
In order to configure Logging block, expand logging settings by clicking the icon on the left hand side as marked in red below image.
Step 5: Add Database Trace listener
From Logging Target Listeners selecting the + opens 'Add Logging Target Listeners'.
Choose 'Add Database Trace Listener' from context menu that is opened from
'Add Logging Target Listeners' as shown below screenshot.
Step 6: Choose Database Trace Listener as default listener
Make sure that 'Database Trace listener' is chosen as default listener in Logging settings --> General section as shown in below image.
Note:- By selecting right mouse button on particular configuration section it is feasible to Validate particular section as shown in below image.
Step 7: Enterprise library application block DLL references
Make sure that below mentioned references from Enterprise library API are added to
the service WCF service as shown in below image.
These DLLs are available from Enterprise Library installation at
C:\Program Files\Microsoft Enterprise Library 5.0\Bin
Step 8: Add required 'using' statements
Step 9: Create a method that utilises Logging application block to log data to database.
Create a private LogWriter variable as below;
Logger method can be similar to the one below or it can have more parameters.
Step 10: Test the functionality with a client instance
Running the client app with above should log data to Logging database, which can be installed from scripts provided with Hands-on-Labs referenced below.
Creating Logging database
Note that Logging database can be created by running the SQL script provided with Enterprise Library 5.0 Hands on labs, which can be downloaded at