I don't know why he told you

What was there to gain but hurting you and betraying your trust in him. The question is, can you forgive him. Better yet, can you forgive him and move on with your life?
Is your marriage worth saving? You got some real issues facing you. Getting trust built back up is going to be hard. You and the AH sit down and talk Y? Did he say, I was not getting attention at home etc.
What ever you decide, you need to get over the resentment you have in your heart right now. Forgive him for your sake not his. Why carry the grudge around andlet it eat at you like cancer. This way, you can walk away from your marriage knowing you took the high road
hugs
chris