Example #1
0
        public static ErrorReportInfo GetInfo(int _error_ID)
        {
            ErrorReportInfo retVal = null;
            SqlConnection   dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand      dbCmd  = new SqlCommand("Main_ErrorReport_GetInfo", dbConn);

            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Error_ID", _error_ID);
            try
            {
                dbConn.Open();
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.Read())
                {
                    retVal                = new ErrorReportInfo();
                    retVal.Error_ID       = Convert.ToInt32(dr["Error_ID"]);
                    retVal.Error_Url      = Convert.ToString(dr["Error_Url"]);
                    retVal.Error_String   = Convert.ToString(dr["Error_String"]);
                    retVal.Error_Datetime = Convert.ToDateTime(dr["Error_Datetime"]);
                }
                if (dr != null)
                {
                    dr.Close();
                }
            }
            finally
            {
                dbConn.Close();
            }
            return(retVal);
        }
        public void ReportException(ExceptionContext exceptionContext)
        {
            var errorInfo = new ErrorReportInfo(exceptionContext, this.CustomActivityMessage);

            errorInfo.Generate();
            _log.Error("Unexpected error: {0}", errorInfo.ReportText);

            if (errorInfo.Errors.Any())
            {
                _log.Error("Error generating error report. Original exception: {0}", exceptionContext.Exception);
            }

            // sending mail can be a little slow, don't delay end user seeing error page
            Task.Factory.StartNew(
                state =>
            {
                var errorReport = (ErrorReportInfo)state;
                DependencyResolver.Current.GetService <IErrorEmailer>().SendErrorEmail(errorReport);
            },
                errorInfo).ContinueWith(t =>
            {
                if (null != t.Exception)
                {
                    _log.Error("Error sending email: " + t.Exception.ToString());
                }
            });
        }
Example #3
0
        public static void Update(ErrorReportInfo _errorReporInfo)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand    dbCmd  = new SqlCommand("Main_ErrorReport_Update", dbConn);

            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Error_ID", _errorReporInfo.Error_ID);
            dbCmd.Parameters.AddWithValue("@Error_Url", _errorReporInfo.Error_Url);
            dbCmd.Parameters.AddWithValue("@Error_String", _errorReporInfo.Error_String);
            dbCmd.Parameters.AddWithValue("@Error_Datetime", _errorReporInfo.Error_Datetime);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }
Example #4
0
        public static int Insert(ErrorReportInfo _errorReporInfo)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand    dbCmd  = new SqlCommand("Main_ErrorReport_Insert", dbConn);

            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Error_Url", _errorReporInfo.Error_Url);
            dbCmd.Parameters.AddWithValue("@Error_String", _errorReporInfo.Error_String);
            dbCmd.Parameters.AddWithValue("@Error_Datetime", _errorReporInfo.Error_Datetime);
            dbCmd.Parameters.AddWithValue("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                return((int)dbCmd.Parameters["@RETURN_VALUE"].Value);
            }
            finally
            {
                dbConn.Close();
            }
        }
Example #5
0
        public void SendErrorEmail(ErrorReportInfo errorInfo)
        {
            try
            {
                var subject = string.Format("{0} Error", Assembly.GetExecutingAssembly().GetName().Name);

                if (null != errorInfo.Server && null != errorInfo.Location &&
                    !string.IsNullOrWhiteSpace(errorInfo.Location.ControllerAction) &&
                    !string.IsNullOrWhiteSpace(errorInfo.Server.HostName))
                {
                    subject = string.Format("{0}: {1} - {2}", subject, errorInfo.Server.HostName,
                                            errorInfo.Location.ControllerAction);
                }

                var to = AppSettings.Default.Email.ErrorMessageTo;
                _mailer.SendMail(to, subject, errorInfo.ReportHtml);

                _log.Info("Sent email: {0} to {1}", subject, to);
            }
            catch (Exception ex)
            {
                _log.Error("Error sending error report email: {0}", ex);
            }
        }