Tuesday, October 11, 2011

Send Mail on Exception With Extensible Method


class Program
    {
        static void Main(string[] args)
        {
            try
            {
                throw new Exception("Expection");
            }
            catch (Exception ex)
            {
                ex.SendErrorEmail();
            }
        }
    }
    public static class MyExtension
    {
        public static void SendErrorEmail(this Exception ex)
        {
            //Write your send mail code
            //....
            smtpClient.Send(mailMessage);
        }
    }

No comments:

Post a Comment