Bad situation to say the least, often it takes losing those we love the most to see how much we do love them. I am never a advocate for lying............the fact is your wife has the right to know what her marriage is really about and given the opportunity to decide what she wants with all the facts on the table.
With that being said, it will not be easy. You have two options really.
The first option is to hold off telling her, if you get a slap on the wrist you walk away with no harm no foul. The problem is these things never seem to stay under wraps. Should she be checking online sometime and bring up the court case you are going to have a lot of explaining to do. Not to mention all the other ways that she could find out. While keeping silent may seem like the best bet the reality of it is there are so many different variables where she could find out. And if you fail to tell her before she finds out she is going to assume you learned nothing since you continued to lie to her.
The second option is to face the music, not only is this prospect scary but it could cost you your wife. I wish I could tell you otherwise but some women are stickers about these kinds of things and the fact is even if she does forgive you she is going to be mad as all get out at you! Though even knowing all this, it is still your best route.
Here is why, women always assume a man is sneaky and convincing. If you wait to tell her until after the hearing (Assuming you get in big trouble) she is going to wonder if you would have hidden this from her if all you got was a slap on the wrist (And with good cause since that is what we are debating here). Her thinking this is FAR WORSE then any anger you will get over your actions. The reason is she is going to assume, that you only told her because you had to and next time you will just be more careful.
By telling her now, you get to at least pull the (I made a mistake) card. The fact is by being up front and honest about the whole situation you are easier to forgive.
Now here is the situation, when telling her be prepared for anger. Now this means accept fault. Do not look for excuses and do not blame this on the marriage. Be honest, the best way to be honest is to sit down before hand and be honest with yourself. No matter how confused you were about your marriage that is no excuse to do what you did. Tell her the truth, you allowed yourself to get sucked into the darker side of the Internet and slowly over time allowed yourself to make bad choices until you hit rock bottom and screwed up. She is far more apt to forgive you with the truth then with excuses. The minute you say "Well I was confused about how I felt" or "Things have been rough in our marriage" you are going to shoot yourself in the foot. Women look at this like you are blaming them..........pretty much might as well say "If you were a better wife, and made me happy I would not have done this" Which is like waving a red flag in front of a bull. You must be very careful how you handle what you say. Even the slightest excuse to try and make you look better could backfire.
By being honest, and saying "Honey I know this is my fault, and you have been a excellent wife" you are showing her that you know what you did, you know you made a mistake, and you know you are never going to do it again. Women can often forgive a man........but only if he takes responsibility for his actions. You can also drop the hint that you could have hidden this (Since you may walk away with a slap on the wrist) but you instead made the choice to come clean with her because you love her and keeping it hidden would be wrong.
Now she is not going to be happy, but she has the right to know what you are doing and the right to make her choices knowing the full score. I would strongly suggest that YOU bring up marriage counseling. By doing this you show her that you know you messed up and are wanting to ensure it does not happen again.
In the end it is your choice what you do.......no one can force you to be honest. But honesty often has a habit of working itself out and making a relationship stronger then before.