no entries logged in database- EL 6

Topics: Data Access Application Block, Logging Application Block
Aug 6, 2014 at 11:01 AM
Edited Aug 6, 2014 at 11:05 AM
i am trying to log exceptions to database but by using logging,database block only.

The structure is ,database=DLAdmin,Table=ExceptionLog.

I modified the LoggingDatabase.sql file by
  1. adding use "use [DLAdmin]" and eliminating create database.
  2. i also change table Log to ExceptionLog.
I ran the sql in sql studio.

the config file is
<?xml version="1.0" encoding="utf-8"?>
<configuration>
     <configSections>    
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
  </configSections>
  <appSettings>
    <add key="ServerName" value="DELL-PC\SQLEXPRESS"/>
    <!-- User token for API server access, required -->
    <add key="DataBaseName" value="DLAdmin"/>
  </appSettings>
    <startup> 
        
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>

     <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General">    
       <listeners>      
                  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Database Trace Listener" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" formatter="Text Formatter" databaseInstanceName="Logging" writeLogStoredProcName="WriteLog"  addCategoryStoredProcName="AddCategory">   
           
         </add>
       
  </listeners>    
  <formatters>   
    <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter" template="Timestamp: {timestamp}{newline} Message: {message}{newline} Category: {category}{newline} Priority: {priority}{newline} EventId: {eventid}{newline} Severity: {severity}{newline} Title:{title}{newline} Machine: {localMachine}{newline} App Domain: {localAppDomain}{newline} ProcessId: {localProcessId}{newline} Process Name: {localProcessName}{newline} Thread Name: {threadName}{newline} Win32 ThreadId:{win32ThreadId}{newline} Extended Properties: {dictionary({key} - {value}{newline})}">   
      
    </add>
  </formatters>
  
<categorySources>   
  <add name="General" switchValue="All">         
  <listeners>       
    <add name="Database Trace Listener">
     </add>
  </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="Information" name="Logging Errors &amp; Warnings">
  <listeners>
  <add name="Database Trace Listener"/>
  </listeners>
 </errors>
   </specialSources>
     
     
  </loggingConfiguration> 
     

  
  <connectionStrings>  
    <add name="Logging" providerName="System.Data.SqlClient" connectionString="Data Source=DELL3-PC\SQLEXPRESS;Initial Catalog=DLAdmin" />
    
  </connectionStrings>


</configuration>

The c# code in app.xaml.cs is
   DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(new     SystemConfigurationSource(true).GetSection));
  LogWriterFactory logWriterFactory = new LogWriterFactory();

  logger=logWriterFactory.Create(); 
Then I call the following code from catch blocks

            LogEntry le = new LogEntry();
            le.Severity =evttype;
            le.Message = strmsg;
            le.Priority = priority;
    
            try
            {

                App.logger.Write(entry);
            }
The code is executing.but no entry is found in the exceptionlog table. I thought I have done everything I found in the reference samples

what am I missing here?
Aug 11, 2014 at 4:39 AM
If you change the Log table in the database then you would also have to change the stored procedure that writes to the Log table to write to the new table name.

The configuration itself is valid but what you should do is add a new trace listener (e.g. flat file trace listener) and set the error special source to the flat file trace listener:
            <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                fileName="trace.log" />
 <errors switchValue="Information" name="Logging Errors &amp; Warnings">
  <listeners>
  <add name="Flat File Trace Listener"/>
  </listeners>
 </errors>
Once that is configured you should be able to see the exact error that is occurring when you try to write to the database. In general, use a different trace listener than the "main" application trace listener for the errors special source so that you can see (non-transient) errors that occur while writing to the "main" application trace listener.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to