public void LogException(typeLogMessage MessageID, typeUserActions UserAction, string description, string urlpage, ref Exception ex) { if (ex.GetType() == typeof(SqlException)) { StringBuilder sb = new StringBuilder(); try { SqlException sqlEx = (SqlException)ex; for (int i = 0; i < sqlEx.Errors.Count; i++) { sb.Append("Index #"); sb.AppendLine(i.ToString()); sb.Append("Message: "); sb.AppendLine(sqlEx.Errors[i].Message); sb.Append("LineNumber: "); sb.AppendLine(sqlEx.Errors[i].LineNumber.ToString()); sb.Append("Source: "); sb.AppendLine(sqlEx.Errors[i].Source); sb.Append("Procedure: "); sb.AppendLine(sqlEx.Errors[i].Procedure); } } finally { description = description + sb.ToString(); } } description = description + " logging exception: EX:" + ex.Message + " stack: " + ex.StackTrace; if (ex.InnerException != null) { description += " Innerexception: " + ex.InnerException.Message + " stack: " + ex.InnerException.StackTrace; } try { description += " USUARIO: " + new BasePage().UserID + " NOMBRE: " + new BasePage().CurrentUserName; description += "<BR />Page:" + HttpContext.Current.Request.Url.ToString(); } catch {} try { String sTo = "[email protected], [email protected]"; StringBuilder Subject = new StringBuilder(); Subject.Append("Exception: "); Subject.Append(ex.Message); StringBuilder Body = new StringBuilder(); Body.Append("Time: "); Body.Append(Utils.Now.ToString("dd/MM/yyyy HH:mm:ss")); Body.Append("<br />"); Body.Append("Message: "); Body.Append(ex.Message); Body.Append("<br />"); Body.Append("Stack: "); Body.Append(ex.StackTrace); Body.Append("<br />"); Body.Append("FullDesc: "); Body.Append(description); Body.Append("<br />"); Body.Append(" :-( do not let this happen again"); try { EMailUtils.SendTextEmail(sTo, Subject.ToString(), Body.ToString(), true); } catch {} } catch {} this.LogMessage(MessageID, UserAction, new BasePage().UserID, description, urlpage); }