...you're not a failure. Affairs are HIGHLY addictive, and without complete no-contact, a transparency plan, and GOOD marriage counseling/family therapy, with a FT who specializes in infidelity, the recidivism rate is VERY high -- upwards of 90%.
So it isn't you ... it's him.
Just learn from your mistakes, and protect yourself going forward. Time to ditch the "be his friend" thing, and start worrying more about being "Mamabear." Your kids are going to need you in the next 24 months, in a big way.
"What is best for my kids is best for me"
Persevere = happily being patient over a long period of time