2015-11-19 1 views
1

J'ai implémenté un gestionnaire d'exceptions personnalisé qui fonctionne, à l'exception des mappages de la politique de configuration xml. Les cartographie fonctionne avec la norme Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandlerEntlib Mappage d'exceptions personnalisées manquantes Mappages

Ma mise en œuvre

[ConfigurationElementType(typeof(CustomHandlerData))] 
    public class IdentityFaultContractExceptionHandler : IExceptionHandler 
    { 
     public IdentityFaultContractExceptionHandler(NameValueCollection attributes) 
     { 
     } 

     public IdentityFaultContractExceptionHandler(Type faultContractType, NameValueCollection attributes) 
     { 
     } 

     public IdentityFaultContractExceptionHandler(Type faultContractType, string exceptionMessage, NameValueCollection attributes) 
     { 
     } 

     public IdentityFaultContractExceptionHandler(IStringResolver exceptionMessageResolver, Type faultContractType, NameValueCollection attributes) 
     { 
     } 

     public Exception HandleException(Exception exception, Guid handlingInstanceId) 
     { 
      return new Exception(); 
     } 

et une partie de la configuration

<add name="All Exceptions" type="System.Exception, mscorlib" postHandlingAction="ThrowNewException"> 
      <exceptionHandlers> 
      <add type="MyClass.IdentityFaultContractExceptionHandler, MyClass" exceptionMessage="An error occurred in the service." faultContractType="MyClass.UnexpectedServerFault, MyClass" name="Fault Contract Exception Handler" > 
       <mappings> 
       <add source="{Message}" name="Message" /> 
       </mappings> 
      </add> 
      </exceptionHandlers> 
     </add> 

Lorsque je supprime les travaux de service du nœud mappping, quand j'ajoute, je suis erreur: élément unrecognize mappings.

Répondre

1

Si vous utilisez un attribut CustomHandlerData, votre configuration doit utiliser des attributs XML qui sont ensuite passés en tant que NameValueCollection au constructeur du gestionnaire personnalisé. Si vous voulez avoir du XML personnalisé, vous devrez utiliser Full Design-time Integration. Si vous voulez aller dans cette direction, vous devriez regarder le code source FaultContractExceptionHandlerData puisque votre code serait probablement assez similaire.