/// <summary> /// <see cref="AggregateException"/>-s are logged and those with a single inner exception, processes the inner exception. /// <see cref="DbUpdateConcurrencyException"/> are logged as info and swallowed. /// Exceptions for which <see cref="IOrmSpecifics.IsTransient"/> is <see langword="true"/> are logged as warnings and /// rethrown wrapped in a new <see cref="RepeatableOperationException"/>; /// The rest of the exceptions are re-thrown. /// </summary> /// <param name="logExceptionTitle">The log exception title.</param> /// <returns>ExceptionPolicyEntry[].</returns> static ExceptionPolicyEntry[] NoneExceptionPolicyEntries( string logExceptionTitle = LogExceptionTitle) { int eventId = 3500; return(new ExceptionPolicyEntry[] { // log and unwrap new ExceptionPolicyEntry( typeof(AggregateException), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { ExceptionPolicyProvider.CreateLoggingExceptionHandler( logExceptionTitle, eventId++, TraceEventType.Information), new UnwrapAggregateExceptionHandler(NonePolicyName), } ), // log and rethrow new ExceptionPolicyEntry( typeof(Exception), PostHandlingAction.NotifyRethrow, new IExceptionHandler[] { ExceptionPolicyProvider.CreateLoggingExceptionHandler( logExceptionTitle, eventId++, TraceEventType.Error), }) }); }
/// <summary> /// <see cref="AggregateException"/>-s are logged and those with a single inner exception, processes the inner exception. /// <see cref="DbUpdateConcurrencyException"/> are logged as info and swallowed. /// Exceptions for which <see cref="IOrmSpecifics.IsTransient"/> is <see langword="true"/> are logged as warnings and /// re-thrown wrapped in a new <see cref="RepeatableOperationException"/>; /// The rest of the exceptions are re-thrown. /// </summary> /// <param name="logExceptionTitle">The log exception title.</param> /// <returns>ExceptionPolicyEntry[].</returns> static ExceptionPolicyEntry[] ClientWinsExceptionPolicyEntries( string logExceptionTitle = LogExceptionTitle) { int eventId = 3510; return(new ExceptionPolicyEntry[] { // log and unwrap new ExceptionPolicyEntry( typeof(AggregateException), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { ExceptionPolicyProvider.CreateLoggingExceptionHandler( logExceptionTitle, eventId++, TraceEventType.Information), new UnwrapAggregateExceptionHandler(ClientWinsPolicyName), } ), // log and swallow but the caller must decide how to proceed, e.g. retry or something else new ExceptionPolicyEntry( typeof(DbUpdateConcurrencyException), PostHandlingAction.None, new IExceptionHandler[] { ExceptionPolicyProvider.CreateLoggingExceptionHandler( logExceptionTitle, eventId++, TraceEventType.Warning), }), // log, possibly wrap in RepeatableOperationException and (re)throw new ExceptionPolicyEntry( typeof(Exception), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { ExceptionPolicyProvider.CreateLoggingExceptionHandler( logExceptionTitle, eventId++, TraceEventType.Error), new EFRepositoryExceptionHandler(), }) }); }
static ExceptionPolicyEntry[] FaultFromExceptionPolicyEntries( string logExceptionTitle = LogExceptionTitle) { int eventId = 3900; return(new ExceptionPolicyEntry[] { new ExceptionPolicyEntry( typeof(Exception), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { ExceptionPolicyProvider.CreateLoggingExceptionHandler( logExceptionTitle, eventId), new ServiceFaultFromExceptionHandler(), }) }); }
/// <summary> /// Creates an exception policy entry that logs the exception and throws a new fault exception created out of the original exception. /// </summary> /// <typeparam name="TException">The type of the exception.</typeparam> /// <typeparam name="TFault">The type of the fault contract.</typeparam> /// <param name="eventId">The event identifier.</param> /// <param name="logExceptionTitle">The log exception title.</param> /// <returns>An <see cref="ExceptionPolicyEntry" /> instance.</returns> public static ExceptionPolicyEntry GetThrowFaultExceptionPolicyEntry <TException, TFault>( int eventId, string logExceptionTitle = LogExceptionTitle) { return(new ExceptionPolicyEntry( typeof(TException), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { ExceptionPolicyProvider.CreateLoggingExceptionHandler( logExceptionTitle, eventId), new FaultContractExceptionHandler( typeof(TFault), new NameValueCollection { ["Id"] = "{Guid}", ["HandlingInstanceId"] = "{Guid}", }), })); }
/// <summary> /// Flattens <see cref="AggregateException"/>-s and after that, /// Exceptions for which <see cref="IOrmSpecifics.IsTransient"/> is <see langword="true"/> are logged as warnings and rethrown /// wrapped in a new <see cref="RepeatableOperationException"/>; /// the rest of the exceptions are logged and re-thrown. /// </summary> /// <param name="logExceptionTitle">The log exception title.</param> /// <returns>ExceptionPolicyEntry[].</returns> static ExceptionPolicyEntry[] StoreWinsExceptionPolicyEntries( string logExceptionTitle = LogExceptionTitle) { int eventId = 3520; return(new ExceptionPolicyEntry[] { // log and unwrap new ExceptionPolicyEntry( typeof(AggregateException), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { ExceptionPolicyProvider.CreateLoggingExceptionHandler( logExceptionTitle, eventId++, TraceEventType.Information), new UnwrapAggregateExceptionHandler(StoreWinsPolicyName), } ), // log, possibly wrap in RepeatableOperationException and throw new ExceptionPolicyEntry( typeof(Exception), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { ExceptionPolicyProvider.CreateLoggingExceptionHandler( logExceptionTitle, eventId++, TraceEventType.Error), new EFRepositoryExceptionHandler(), }) }); }