EntLib 5.0 - SQL Database Logging not working

Topics: Data Access Application Block, General discussion, Logging Application Block
Jun 13, 2011 at 12:26 PM

I have created a sample web page (VS 2010) to test SQL 2008 database logging on Button click.  The below code executes without exception but  there is nothing  inserted to the Log table in database.

I have all the required tables and SPs created in the Db. Also, i tried running the SQL profiler but dont see any logs moving.

Please help. Thanks!

LogEntry logEntry = new LogEntry();
logEntry.EventId = 1234;
logEntry.Priority = 1;
logEntry.Severity = System.Diagnostics.TraceEventType.Information;
logEntry.Title = "Logging";
logEntry.Message = string.Format("Test Message");
logEntry.Categories.Add("General");   

Logger.Write(logEntry); 

  This is how my Web.Config looks like:  
   

<configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>


  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General">
    <listeners>
      <add name="Database Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        databaseInstanceName="TEST_DB" writeLogStoredProcName="WriteLog"
        addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
        traceOutputOptions="None" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events"/>       
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Database Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <dataConfiguration defaultDatabase="TEST_DB" />
  <connectionStrings>
    <add name="TEST_DB" connectionString="Server=xxxxxx;Initial Catalog=TEST_DB;id=test;password=password1"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

 

 

 

Jun 14, 2011 at 1:54 AM

Hi,

Your config looks fine. Have you executed the sql script found on EntLib50Src\Blocks\Logging\Src\DatabaseTraceListener\Scripts to create the logging database?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jun 14, 2011 at 1:59 AM

No, I did not execute sql scripts from the above path. Instead I had my own database already in place, just used the provided sql scripts to create tables and stored procedures. 

Jun 14, 2011 at 2:37 AM
Edited Jun 14, 2011 at 2:37 AM

Can you try adding Event Trace Listener and point your Logging Errors & Warnings Category there so we can retrieve the exception thrown (if any)? Currently your Logging Errors & Warnings Category is also pointing to your Database Trace Listener.


 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 14, 2011 at 3:59 AM

Thanks Noel for a prompt reply. I have tried doing the same with Event Logs as well, but I think am missing something on the permissions. Its not able to write to "Application" event logs.

Could you pls help me with some links or steps to configure access rights on event logs? Thanks!

 

Jun 14, 2011 at 4:24 AM

I got the event logs after setting "Network Service" permissions in Registry.

Message: Tracing to LogSource 'General' failed. Processing for other sources will continue. 
See summary information below for more information. Should this problem persist, stop the service and check the configuration file(s) for possible error(s) in the configuration of the categories and sinks.


Summary for Enterprise Library Distributor Service:
======================================
--> 
Message: 
Timestamp: 6/14/2011 4:14:57 AM
Message: Test Message
Category: General
Priority: 1
EventId: 1234
Severity: Error
Title:Enterprise Library Logging
Machine: xxxxxx
App Domain: /LM/w3svc/1/ROOT/WebLogging-2-129524984699598927
ProcessId: 344
Process Name: c:\sysroot\system32\inetsrv\w3wp.exe
Thread Name: 
Win32 ThreadId:1120
Extended Properties: 
--> MachineName: xxxxxx
--> TimeStamp: 6/14/2011 4:14:57 AM
--> FullName: Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
--> AppDomainName: /LM/w3svc/1/ROOT/WebLogging-2-129524984699598927
--> WindowsIdentity: NT AUTHORITY\NETWORK SERVICE

Exception Information Details:
======================================
Exception Type: System.ArgumentException
Message: Keyword not supported: 'id'.
ParamName: NULL
Data: System.Collections.ListDictionaryInternal
TargetSite: System.Data.Common.NameValuePair ParseInternal(System.Collections.Hashtable, System.String, Boolean, System.Collections.Hashtable, Boolean)
HelpLink: NULL
Source: System.Data

StackTrace Information Details: 
======================================
   at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
   at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
   at System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value)
   at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
   at Microsoft.Practices.EnterpriseLibrary.Data.Database.CreateConnection()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener.ExecuteStoredProcedure(LogEntry logEntry)
   at Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
   at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.TraceListenerWrapper.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogSource.TraceData(TraceEventType eventType, Int32 id, LogEntry logEntry, TraceListenerFilter traceListenerFilter, TraceEventCache traceEventCache)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl.ProcessLog(LogEntry log, TraceEventCache traceEventCache)





Jun 14, 2011 at 4:32 AM

Thanks Noel for your help. I got it fixed. The problem seem to be in web.config db connection string.

The userid and password attributes should follow format as "uid="xxxx";pwd="zzzz"

 

Jun 14, 2011 at 4:43 AM
Edited Jun 14, 2011 at 4:46 AM

I've overlooked that part. Anyways, thanks for sharing this out :)

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com