2015-11-19 45 views
1

我实现了自定义异常处理程序,其工作原理,除了从xml配置策略映射。这些映射标准Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandlerEntlib自定义异常处理程序缺失映射

我实现

[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(); 
     } 

和配置

<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> 

的一部分工作当我删除mappping节点服务的工作原理,当我添加,然后我得到了错误:unrecognize元素mappings

回答

1

如果您使用的是CustomHandlerData属性,那么你的配置需要使用哪个然后得到传过来的NameValueCollection到自定义处理程序构造XML属性。如果你想要定制XML,那么你将不得不使用Full Design-time Integration。如果你想要走这条路,那么你应该看看FaultContractExceptionHandlerData源代码,因为你的代码可能非常相似。