Cant Log or Replace a FaultContract<FaultType> exception

Topics: Exception Handling Application Block
Nov 30, 2009 at 6:27 PM

Hi

I have this problem using the Exception Handling App Block:

After adding an Exception Policy and Configuring a Fault Contract Exception Handler for it, I try to Log the FaultContract<FaultType> resulting exception by adding a new Exception Policy and it's correspondent Logging Handler, but this doesn't work, I've been trying with both Replace & Wrap Handler but it doesn't work either.

I added all this libraries to my project so I think it isn't the problem:

Microsoft.Practices.EnterpriseLibrary.Common.dll

Microsoft.Practices.EnterpriseLibrary.Data.dll

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.dll

Microsoft.Practices.ObjectBuilder2.dll

 

Please, Can someone help me ?

 

Dec 1, 2009 at 7:05 AM

Hi,

Do you mean that the logging handler is not together with the WCF exception handler in one policy? Can you post your config?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 2, 2010 at 3:47 PM

Hi

I appreciate a lot your help, Thank you very much.

Here is my .config file content:

Thanks again

 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add source="Enterprise Library Logging" 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}&#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=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </add>
      <add switchValue="All" name="MsmqCategory" />
    </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="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="Exception Policy">
        <exceptionTypes>
          <add type="System.ServiceModel.FaultException`1[[SampleDalService.ServiceFault, SampleDalService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="None" name="FaultException&lt;ServiceFault&gt;">
            <exceptionHandlers>
              <add logCategory="General" 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>
        </exceptionTypes>
      </add>
      <add name="WCF Exception Shielding">
        <exceptionTypes>
          <add type="System.NullReferenceException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException" name="NullReferenceException">
            <exceptionHandlers>
              <add exceptionMessage="Custom Message" faultContractType="SampleDalService.ServiceFault, SampleDalService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="Fault Contract Exception Handler">
                <mappings>
                  <add source="Guid" name="Id" />
                  <add source="Message" name="MessageText" />
                </mappings>
              </add>
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
  <system.serviceModel>
    <services>
      <service name="SampleDalService.SampleService" behaviorConfiguration="MexSampleServiceBehaviorConfiguration">
        <endpoint address="http://localhost:8080/SampleService" binding="basicHttpBinding" contract="SampleDalService.ISampleService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MexSampleServiceBehaviorConfiguration">
          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8080/SampleService/Mex" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="SecureLessAndMaximizedReceivedMessageSize" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
        <binding name="BasicHttpBinding_ISampleService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8080/SampleService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleService" contract="SampleServiceReference.ISampleService" name="BasicHttpBinding_ISampleService" />
    </client>
  </system.serviceModel>
</configuration>

Feb 3, 2010 at 4:30 AM

Your config seems fine.  Did you add a reference to ExceptionHandling.Logging assembly?  Have you verified that you can log to the event viewer using Logger.Write outside a WCF service?

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 3, 2010 at 9:50 PM

Yes I added ExceptionHandling.Logging.dll and I also can log to event viewer using Logger.Write. My problem is that I can't do nothing, including logging, when using ExceptionHandling.

Feb 4, 2010 at 4:18 AM

Hi,

I just dont understand, why would you log the FaultContract<FaultType> or do you intent to log the original exception then have the fault contract handler do the transformation of the exception before sending it back to the client as faultcontract.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 8, 2010 at 7:58 AM

So you can perform logging when calling Logger.Write but can't when you use it in conjuction with the EHAB, is that right?

In your service interface, which exception policy did you use?  Is it the default one or the "Exception Policy" policy? 

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 8, 2010 at 7:57 PM

HI

I have solved the problem, although I'm not sure I know which was.

Today morning I rewrite all my demo and woala! it worked.

I really appreciate your help. Thank you for everything

hope to count with you in another time