I'm trying to capture through Action onBreak, but apparently it never throws the exception on the screen.
using Polly;
using System;
using System.Collections.Generic;
namespace CircuitBreakingPolly
{
public class Program
{
public static int n1 = 2;
public static int n2 = 0;
private static List<Produtos> produtos = new List<Produtos>();
static void Main(string[] args)
{
var result = Execute(() => Divisao(n1, n2), () => Divisao(2, 2));
Console.WriteLine(result.ToString());
Console.ReadKey();
}
public static TResult Execute<TResult, TReset>(Func<TResult> action, Func<TReset> actionReset)
{
return Policy
.Handle<DivideByZeroException>()
.CircuitBreaker(4, TimeSpan.FromMinutes(1), onBreak: (exception, timespan, context) =>
{
Console.Write(exception.Message, timespan);
}
, onReset: (context) =>
{
actionReset.Invoke();
}
, onHalfOpen: () =>
{
actionReset.Invoke();
})
.Execute(action);
}
private static int Divisao(int n1, int n2)
{
return n1 / n2;
}
internal static void AtualizarNumero(Exception e, int n)
{
n2 = n;
PoliticasManipulacaoPolly.Log(e);
}
}
}