/// <summary> /// Category name to log <see cref="Exception"/> under. This should align with a category name defined through the <see cref="LoggingConfigurationSourceBuilderExtensions"/> extensions. /// </summary> /// <param name="context">Interface to extend to provide this handler fluent interface.</param> /// <param name="categoryName">Name of the category.</param> /// <returns></returns> public static IExceptionConfigurationLoggingProvider LogToCategory(this IExceptionConfigurationAddExceptionHandlers context, string categoryName) { if (string.IsNullOrEmpty(categoryName)) { throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "categoryName"); } return(new ExceptionConfigurationLoggingProviderBuilder(context, categoryName)); }
protected override void Arrange() { configurationSourceBuilder = new ConfigurationSourceBuilder(); policy = configurationSourceBuilder .ConfigureExceptionHandling() .GivenPolicyWithName(policyName); exception = policy.ForExceptionType(exceptionType); }
public ExceptionConfigurationReplaceWithBuilder(IExceptionConfigurationAddExceptionHandlers context, Type replacingExceptionType) : base(context) { replaceHandlerData = new ReplaceHandlerData() { Name = replacingExceptionType.FullName, ReplaceExceptionType = replacingExceptionType }; base.CurrentExceptionTypeData.ExceptionHandlers.Add(replaceHandlerData); }
public ExceptionConfigurationWrapHandlerBuilder(IExceptionConfigurationAddExceptionHandlers context, Type wrappingExceptionType) : base(context) { handlerData = new WrapHandlerData() { Name = wrappingExceptionType.FullName, WrapExceptionType = wrappingExceptionType }; CurrentExceptionTypeData.ExceptionHandlers.Add(handlerData); }
public ExceptionConfigurationLoggingProviderBuilder(IExceptionConfigurationAddExceptionHandlers context, string categoryName) : base(context) { logHandler = new LoggingExceptionHandlerData { Name = categoryName, LogCategory = categoryName, FormatterType = typeof(TextExceptionFormatter) }; base.CurrentExceptionTypeData.ExceptionHandlers.Add(logHandler); }
public ExceptionConfigurationCustomHandlerBuilder(IExceptionConfigurationAddExceptionHandlers context, Type customHandlerType, NameValueCollection customHandlerSettings) : base(context) { var customHandler = new CustomHandlerData { Name = customHandlerType.FullName, Type = customHandlerType }; customHandler.Attributes.Add(customHandlerSettings); CurrentExceptionTypeData.ExceptionHandlers.Add(customHandler); }
/// <summary> /// Replace exception with new exception type. /// </summary> /// <param name="context">Interface to extend to add ReplaceWith options.</param> /// <param name="replacingExceptionType">Replacement <see cref="Exception"/> type.</param> /// <returns></returns> public static IExceptionConfigurationReplaceWithProvider ReplaceWith(this IExceptionConfigurationAddExceptionHandlers context, Type replacingExceptionType) { if (replacingExceptionType == null) { throw new ArgumentNullException("replacingExceptionType"); } if (!typeof(Exception).IsAssignableFrom(replacingExceptionType)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionTypeMustDeriveFromType, typeof(Exception)), "replacingExceptionType"); } return(new ExceptionConfigurationReplaceWithBuilder(context, replacingExceptionType)); }
/// <summary> /// Replace exception with new exception type. /// </summary> /// <typeparam name="T">Replacement <see cref="Exception"/> type.</typeparam> /// <returns></returns> public static IExceptionConfigurationReplaceWithProvider ReplaceWith <T>(this IExceptionConfigurationAddExceptionHandlers context) where T : Exception { return(ReplaceWith(context, typeof(T))); }
protected override void Arrange() { base.Arrange(); exception = policy.ForExceptionType(exceptionType); }
/// <summary> /// Initializes a new instance of the ExceptoinHandlerConfigurationExtensions /// </summary> /// <param name="context">The context for configuration.</param> /// <remarks> /// This constructor expects to the find the implementor of <paramref name="context"/> provide /// the <see cref="IExceptionConfigurationForExceptionTypeOrPostHandling"/> and <see cref="IExceptionHandlerExtension"/> interfaces. /// </remarks> protected ExceptionHandlerConfigurationExtension(IExceptionConfigurationAddExceptionHandlers context) { this.Context = (IExceptionConfigurationForExceptionTypeOrPostHandling)context; Debug.Assert(typeof (IExceptionHandlerExtension).IsAssignableFrom(context.GetType())); }
/// <summary> /// Handle the <see cref="Exception"/> with a custom exception handler. /// </summary> /// <param name="context">Interface to extend to add custom handler options.</param> /// <typeparam name="T">The Type of the custom handler.</typeparam> /// <returns></returns> public static IExceptionConfigurationForExceptionTypeOrPostHandling HandleCustom <T>(this IExceptionConfigurationAddExceptionHandlers context) where T : IExceptionHandler { return(HandleCustom(context, typeof(T))); }
/// <summary> /// Handle the <see cref="Exception"/> with a custom exception handler. /// </summary> /// <param name="context">Interface to extend to add custom handler options.</param> /// <param name="customHandlerType">The <see cref="Type"/> of the custom handler. /// <remarks>This must derive from <see cref="IExceptionHandler"/></remarks></param> /// <returns></returns> public static IExceptionConfigurationForExceptionTypeOrPostHandling HandleCustom(this IExceptionConfigurationAddExceptionHandlers context, Type customHandlerType) { return(HandleCustom(context, customHandlerType, new NameValueCollection())); }
/// <summary> /// Initializes a new instance of the ExceptoinHandlerConfigurationExtensions /// </summary> /// <param name="context">The context for configuration.</param> /// <remarks> /// This constructor expects to the find the implementor of <paramref name="context"/> provide /// the <see cref="IExceptionConfigurationForExceptionTypeOrPostHandling"/> and <see cref="IExceptionHandlerExtension"/> interfaces. /// </remarks> protected ExceptionHandlerConfigurationExtension(IExceptionConfigurationAddExceptionHandlers context) { this.Context = (IExceptionConfigurationForExceptionTypeOrPostHandling)context; Debug.Assert(typeof(IExceptionHandlerExtension).IsAssignableFrom(context.GetType())); }
/// <summary> /// Handle the <see cref="Exception"/> with a custom exception handler. /// </summary> /// <param name="context">Interface to extend to add custom handler options.</param> /// <param name="customHandlerType">The <see cref="Type"/> of the custom handler. </param> ///<param name="customHandlerSettings">Name-Value collection of attributes the custom handler can use to initialize itself.</param> ///<returns></returns> public static IExceptionConfigurationForExceptionTypeOrPostHandling HandleCustom(this IExceptionConfigurationAddExceptionHandlers context, Type customHandlerType, NameValueCollection customHandlerSettings) { if (customHandlerType == null) { throw new ArgumentNullException("customHandlerType"); } if (customHandlerSettings == null) { throw new ArgumentNullException("customHandlerSettings"); } if (!typeof(IExceptionHandler).IsAssignableFrom(customHandlerType)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionTypeMustDeriveFromType, typeof(IExceptionHandler)), "customHandlerType"); } return(new ExceptionConfigurationCustomHandlerBuilder(context, customHandlerType, customHandlerSettings)); }
/// <summary> /// Shields an exception in Wcf by wrapping it in with a fault contract type. /// </summary> /// <param name="context">Interface to extend to add ShieldExceptionForWcf options.</param> /// <param name="faultContractType">Fault contract type use when wrapping an exception.</param> /// <param name="faultContractMessage">Exeption message to use on new exception.</param> /// <returns></returns> public static IExceptionConfigurationWcfShieldingProvider ShieldExceptionForWcf(this IExceptionConfigurationAddExceptionHandlers context, Type faultContractType, string faultContractMessage) { if (faultContractType == null) { throw new ArgumentNullException("faultContractType"); } return(new ExceptionConfigurationLoggingProviderBuilder((IExceptionConfigurationForExceptionTypeOrPostHandling)context, faultContractType, faultContractMessage)); }