Writing to Database V3.1 won't work.

Topics: Logging Application Block
Dec 5, 2008 at 7:37 PM
Hi All,

These are the steps I have taken to write my error entries into the SQL database. I  must be doing something wrong. Any help i would greatly appreciated.
It works fine when i wrote to the event log. The config file below I only want to write to my database.


I have the  logger.database.dll file in my solution, I also placed it in the GAC.
I ran the sql file provided with the Enterprise libraries which has created my database, sp's, and tables.
Below is my config file 

<?xml version="1.0" ?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
      defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add databaseInstanceName="Hatch.BizTalk.Router" writeLogStoredProcName="WriteLog"
          addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
          listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
          traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
          name="Hatch.BizTalk.Router" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
          type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
          name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="Hatch.Biztalk.Router">
        <listeners>
          <add name="Hatch.BizTalk.Router" />
        </listeners>
      </add>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Hatch.BizTalk.Router" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Hatch.BizTalk.Router" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Hatch.BizTalk.Router" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Hatch.BizTalk.Router" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <dataConfiguration defaultDatabase="Hatch.BizTalk.Router" />
  <connectionStrings>
    <add name="Hatch.BizTalk.Router" connectionString="Data Source=MISBTS\MISSQLDEV01;Initial Catalog=Logging;Integrated Security=True"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="BizTalk Assemblies;Developer Tools;Tracking;Tracking\interop" />
    </assemblyBinding>
  </runtime>

  <system.runtime.remoting>

    <channelSinkProviders>
      <serverProviders>
        <provider id="sspi" type="Microsoft.BizTalk.XLANGs.BTXEngine.SecurityServerChannelSinkProvider,Microsoft.XLANGs.BizTalk.Engine" securityPackage="ntlm" authenticationLevel="packetPrivacy" />
      </serverProviders>
    </channelSinkProviders>
   
        <application>
            <channels>
                <channel ref="tcp" port="0" name="">
                 <serverProviders>
                     <provider ref="sspi" />
                        <formatter ref="binary" typeFilterLevel="Full"/>
                    </serverProviders>
                </channel>
            </channels>
        </application>
    </system.runtime.remoting>
   
</configuration>


The only other thing I can say is that I get absolutly no errors anywhere. No where in the event log is there any erros. I have also ran SQL server profiler and it seems that the logging sp's never run.

The only thing i can think of is my congif file is bad.


Thank you again,
Greg

Dec 6, 2008 at 3:10 AM
Hi,

Can you please post your sample code of Logging? 

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Dec 8, 2008 at 1:51 PM
The following is the code i used for the Event log logging and it worked.
For logging ot the database i have tried the same code and i have had no luck.

method 1
        TraceEventType convertedEventType = (TraceEventType)eventType;
        Logger.Write(strMessage, "Hatch.BizTalk.Router", iPriority, iEventID, convertedEventType, GUID);

method 2
            LogEntry logEntry = new LogEntry();
            logEntry.EventId = 100;
            logEntry.Categories.Add("Hatch.BizTalk.Router");
            logEntry.Priority = 6;
            logEntry.Severity = System.Diagnostics.TraceEventType.Critical;
            logEntry.Message = "Logging important information";
            logEntry.Title = "Test Entry";
            logEntry.MachineName = Environment.MachineName;
            Logger.Write(logEntry);

Thank You,

Greg
Dec 8, 2008 at 2:11 PM
Hi Greg,

I suggest that you run a SQL Profiler against your app, to check if your sprocs are executed.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Dec 8, 2008 at 2:39 PM
Hi Valiant,

I have tired but nothing is happenong.

i have attached the process to my  code in VS

and i get the following errors in the output window


A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in Microsoft.Practices.EnterpriseLibrary.Logging.dll
The thread '<No Name>' (0x12a8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x12a8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x14b8) has exited with code 0 (0x0).
The thread '<No Name>' (0x14d0) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1548) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x14d0) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x850) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x17ac) has exited with code 0 (0x0).


Thanks,
Greg
Dec 8, 2008 at 4:17 PM

Hi Valiant,

I got it to work. I build in more error handling into my application. Found the following problems.

 

Config file: Special Sources section was incorrect couldnt execute line 33.  Once i fixed that I got the following error

Inner exception: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I had the refrence in my solution but not in the GAC, when I placed the dll into the GAC it started writing to my database.

Again thank you for looking into this.

Regards,
Greg