开发者

Database Trace Listener with Enterprise library 2.0 not logging in database

I am using Database TraceListener for logging. I've executed the CreateLoggingDb.cmd and the Logging Database is in place. My web.config looks like the below.

When an excpetion occurs I try to log it as below.

ExceptionPolicy.HandleException(ex, "PayrollException");

The code runs but it does not log in the database table. Please let me know if the settings in web.config are not correct or the procedure for logging has to be different.

<configuration>
 <configSections>
  <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
  <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
  <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
 </configSections>
 <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
  <listeners>
   <add databaseInstanceName="LoggingConn" writeLogStoredProcName="WriteLog"
        addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
        traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
        name="Database Trace Listener" />

  </listeners>
  <formatters>
   <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=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Text Formatter"/>
  </formatters>
  <categorySources>
   <add switchValue="All" name="General">
    <listeners>
     <add name="Database 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="Database TraceListener"/>
    </listeners>
   </errors>
  </specialSources>
 </loggingConfiguration>
 <exceptionHandling>
  <exceptionPolicies>
   <add name="PayrollException">
    <exceptionTypes>
     <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow" name="Exception">
      <exceptionHandlers>
       <add exceptionMessage="Payroll Application Exception" wrapExceptionType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Wrap Handler"/>
      </exceptionHandlers>
     </add>
    </exceptionTypes>
   </add>
  </exceptionPolicies>
 </exceptionHandling>
 <connectionStrings>
  <add name="Conn" connectionString="Database=Payroll;Server=10.135.158.211;User Id=xanoneappusr;Password=vivekm123;" providerName="System.Data.SqlClient"/>
  <add name="LoggingConn" connectionString="Database=Logging;Server=10.135.1开发者_如何学Go58.211;User Id=xanoneappusr;Password=vivekm123;" providerName="System.Data.SqlClient"/>
 </connectionStrings>
 <appSettings>
  <add key="PayrollApplication" value="Payroll"/>
 </appSettings>
 <system.web>
  <compilation debug="true" batch="false">
   <assemblies>
    <add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
  <roleManager enabled="true"/>
  <authentication mode="Forms"/>
  <membership>
   <providers>
    <clear/>
    <add connectionStringName="Conn" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" applicationName="PayrollApplication" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"/>
   </providers>
  </membership>
 </system.web>
</configuration>#x#


A few places to start looking are:

  1. Did you use EntLibConfig.exe to build the web.config? This is an exe that comes with Enterprise Library, you should find it in the Bin directory of the Enterprise Library install in Program Files - it gives you a reasonably intuitive graphical interface to set up enterprise library for an application: just point it at the config file for your application and set up the things you want.

  2. For database logging you need to configure your connection strings using the Data Access Application Block - you will need another section in your config file for this.

  3. For your database connection string, what authenticaion mode are you using? Does the user identity running the application have write access to the logging database?

  4. Do you have other database connectivity?

Also - if you are running the .Net framework 3.5 you should consider using version 4.1 of the Enterprise Library.

EDIT after config file supplied

Looking at the config file you've attached (you may want to remove the passwords by the way) I think that you are missing a logging exception handler - the only exception handler you appear to have is a wrap exception handler.

Below is an example of one of one of my exception handling policies (from 4.1 of the Enterprise Library but yours should be similar).

<exceptionPolicies>
  <add name="Data Layer Policy">
    <exceptionTypes>
      <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        postHandlingAction="NotifyRethrow" name="Exception">
        <exceptionHandlers>
          <add logCategory="DataLayer" eventId="100" severity="Error" title="Data Layer Exception"
            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>

The wrap handler is used where you want to wrap one exception around another. You can have both a logging handler and a wrap handler if that is needed - the logging handlers fire before the wrapping ones.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜