2015-11-19 44 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源代碼,因爲你的代碼可能非常相似。