locked
Enterprise Library 3.1 database logging RRS feed

  • Question

  • User248475617 posted

    Hi,
    Im new in using Microsoft Enterprise Library 3.1. Im trying to run database Logging.
    I added the required configuration to the web config as mentioned in MSDN library. then I ran the script to generate logging tables and stored procedures.

    I changed the formatter template to keep needed data. below is sample of my code

           
    Dim ologEntry As LogEntry = New LogEntry()
            With ologEntry
                '.Categories.Add("General")
                .Severity = Diagnostics.TraceEventType.Error
                .Title = "MSEntLib3.1"
                .AppDomainName = AppDomain.CurrentDomain.BaseDirectory
                .ProcessName = "TestFunction()"
                .Message = "Informational message"
            End With
    
            Logger.Write(ologEntry)


    I faced an error that there are missing paramters then I modified writeLog stored Procedure to recieve the listed above paramaters, I test it on sql server its working fine, in my web page it doesnt rais an error and not inserting any data to the log table.


    Tuesday, September 22, 2009 5:07 PM

All replies

  • User220959680 posted

    Hello

    Post your complete Web.config for us to have a look and suggest a solution.

    Note that here is a dedicated forum for Microsoft Enterprise Library, you may wish to post your query to get prompt response.

     

    Thanks,

    Wednesday, September 23, 2009 4:55 PM
  • User248475617 posted

    here is my web.config. I would like to remind you that I modified my stored procedure to accept only needed parameters that I mentioned in my previous post.


    <configSections>
        <!--
        This describes the section of the web.config file that is relevant to our needs.
    In our case this tells us that we are ready to use a section called dataConfiguration. The two entries in the type attribute are the class that handles the processing of the web.config file in relation to this section followed by the assembly name to which this refers.
        -->
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <section name="securityCryptographyConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Configuration.CryptographySettings, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </configSections>
    <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
        defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
        <listeners>
          <add databaseInstanceName="ConnectionString" writeLogStoredProcName="WriteLog"
            addCategoryStoredProcName="AddCategory" formatter="Textformatter"
            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="Database Trace Listener" />
          <add fileName="Log\weblog.log" rollSizeKB="0" timeStampPattern="dd-MM-yyyy"
            rollFileExistsBehavior="Overwrite" rollInterval="Month" formatter="Textformatter"
            header="----------------------------------------" footer="----------------------------------------"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            name="Rolling Flat File Trace Listener" />
        </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="Textformatter" />
        </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" />
          <errors switchValue="All" name="Logging Errors &amp; Warnings">
            <listeners>
              <add name="Database Trace Listener" />
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>
    <connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=mvs2005;Password=sa;User ID=sa;Initial Catalog=Caching"
          providerName="System.Data.SqlClient" />
      </connectionStrings>


    Wednesday, September 23, 2009 5:43 PM
  • User220959680 posted

    Here is the working configuration for Logging to database. Check against yours. You should be able to fix your problem. Let you know that you can download free ebook here and check from page No: 280

    <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
        defaultCategory="Information" logWarningsWhenNoCategoriesMatch="true">
        <listeners>
          <add databaseInstanceName="LoggingDb" writeLogStoredProcName="WriteLog"
            addCategoryStoredProcName="AddCategory" formatter="DictionaryFormat"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="DictionaryFormatDatabase" />
          <add toAddress="xyz@xyz.com" fromAddress="xyz@xyz.com"
            subjectLineStarter="Alert: " subjectLineEnder="xyz@xyz.com" smtpServer="xyz@xyz.com"
            smtpPort="25" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            traceOutputOptions="Timestamp" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Email TraceListener" />
          <add fileName="C:\trace2.log" header="----------------------------------------"
            footer="----------------------------------------" formatter="Text Formatter"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="FlatFile TraceListener" />
          <add source="StormTest" formatter="Text Formatter" log="Application"
            machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Formatted EventLog TraceListener" />
        </listeners>
        <formatters>
          <add template="Timestamp: {timestamp}{newline}Title: {title}{newline}{newline}Message: {message}{newline}{newline}Extended Properties:{newline}{dictionary(Key: {key}{tab}{tab}Value: {value}{newline})}"
            type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="DictionaryFormat" />
          <add template="Timestamp: {timestamp}
    
    Message: {message}
    
    Category: {category}
    
    Priority: {priority}
    
    EventId: {eventid}
    
    Severity: {severity}
    
    Title:{title}
    
    Machine: {machine}
    
    Application Domain: {appDomain}
    
    Process Id: {processId}
    
    Process Name: {processName}
    
    Win32 Thread Id: {win32ThreadId}
    
    Thread Name: {threadName}
    
    Extended Properties: {dictionary({key} - {value}
    
    )}"
            type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Text Formatter" />
        </formatters>
        <categorySources>
          <add switchValue="Error" name="Error">
            <listeners>
              <add name="DictionaryFormatDatabase" />
              <add name="Email TraceListener" />
              <add name="FlatFile TraceListener" />
              <add name="Formatted EventLog TraceListener" />
            </listeners>
          </add>
          <add switchValue="Information" name="Information">
            <listeners>
              <add name="DictionaryFormatDatabase" />
              <add name="FlatFile TraceListener" />
            </listeners>
          </add>
          <add switchValue="Warning" name="Warning">
            <listeners>
              <add name="DictionaryFormatDatabase" />
              <add name="FlatFile TraceListener" />
              <add name="Formatted EventLog TraceListener" />
            </listeners>
          </add>
        </categorySources>
        <specialSources>
          <allEvents switchValue="All" name="All Events" />
          <notProcessed switchValue="All" name="Unprocessed Category" />
          <errors switchValue="All" name="Logging Errors & Warnings">
            <listeners>
              <add name="Formatted EventLog TraceListener" />
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>
      <exceptionHandling>
        <exceptionPolicies>
          <add name="UI Policy">
            <exceptionTypes>
              <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                postHandlingAction="None" name="Exception">
                <exceptionHandlers>
                  <add logCategory="Error" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                    formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    name="Logging Handler" />
                </exceptionHandlers>
              </add>
              <add type="System.FormatException, mscorlib, Version=2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                postHandlingAction="None" name="FormatException">
                <exceptionHandlers>
                  <add logCategory="Error" eventId="200" severity="Error" title="Enterprise Library Exception Handling"
                    formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    name="Logging Handler" />
                </exceptionHandlers>
              </add>
            </exceptionTypes>
          </add>
        </exceptionPolicies>
      </exceptionHandling>
      <dataConfiguration defaultDatabase="LoggingDb" />
    


    Let me know how you get on. Post your further queries.

    Thanks,

    Thursday, September 24, 2009 3:50 AM
  • User-47580772 posted

    Hi All,

    I want to log  the errors, but not all. some errors are Userdefined which i dont want to log in the file. only system error should log in the  error log.

     

    Please check the WEB config file.

     

    <

    <

    <

    </

    <

    <!--

    <

    </

    <

    <

    <

    <

    </

    </

    </

    <

    <

    <

    <

    <

    <

    </

    </

    </

    </

    <

    <

    <

    <

    <

    <

    <

    </

    </

    </

    </

    </

    </

     

    loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">listeners>add fileName="C:\Projects\EzRemit\EzRemitWebServiceLog\EZREMIT_Error.log" rollSizeKB="50" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="None" header="----------------------------------------" footer="----------------------------------------" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="RollingFlatFileTraceListener"/>listeners>formatters><add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Text Formatter"/>-->add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: Error Code - SYSTEM_ERROR" 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="General">listeners>add name="RollingFlatFileTraceListener"/>listeners>add>categorySources>specialSources>allEvents switchValue="All" name="All Events"/>notProcessed switchValue="All" name="Unprocessed Category"/>errors switchValue="All" name="Logging Errors &amp; Warnings">listeners>add name="RollingFlatFileTraceListener"/>listeners>errors>specialSources>loggingConfiguration>exceptionHandling>exceptionPolicies>add name="FlatFileLogger">exceptionTypes>add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow" name="Exception">exceptionHandlers>add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Logging Handler"/>exceptionHandlers>add>exceptionTypes>add>exceptionPolicies>exceptionHandling>

     

     

     

    Thanks

     

    Layeeq

    Thursday, August 26, 2010 5:43 AM