/// <summary>
        /// Logs a database event, using the given SqlCommand and SqlException objects.
        /// This is used to keep track of query timeouts and deadlocks.
        /// </summary>
        private void LogDatabaseEvent(string topic, SqlCommand command, SqlException ex)
        {
            StringBuilder info = new StringBuilder();

            // summarize the exception (the stack trace ends in a blank line already)
            info.AppendLine("Exception Type: " + ex.GetType().ToString());
            info.AppendLine("Message: " + ex.Message);
            info.AppendLine("Number: " + ex.Number);
            info.AppendLine("Source: " + ex.Source);
            info.AppendLine("Stack Trace:\r\n" + ex.StackTrace.TrimEnd());

            // summarize the SQL & parameters
            info.AppendLine();
            info.AppendLine("--- Approximate SQL ---");
            info.AppendLine(this.SummarizeSqlCommand(command, true));

            // log it (EventLogger will add some info about the current request)
            //EventLogger.LogEvent(topic, info.ToString());
        }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Util.setCSS();
        labApplicationName.Text = Util.getAppSetting("app://ApplicationName/");
        if (Server.GetLastError() != null)
        {
            string strErrType = "";
            string strErrMsg  = "";

            //SqlException
            if (string.IsNullOrEmpty(strErrType))
            {
                if (Server.GetLastError().GetBaseException() is System.Data.SqlClient.SqlException)
                {
                    //SqlException
                    System.Data.SqlClient.SqlException ex = (System.Data.SqlClient.SqlException)Server.GetLastError().GetBaseException();
                    strErrType += string.Format(SinoPac.WebExpress.Common.Properties.Resources.Msg_ErrorType, ex.GetType().Name);
                    strErrType += " " + string.Format(SinoPac.WebExpress.Common.Properties.Resources.Msg_ErrorCode, ex.ErrorCode);
                    strErrMsg  += ex.Message.ToString();
                }
            }

            //HttpException
            if (string.IsNullOrEmpty(strErrType))
            {
                if (Server.GetLastError().GetBaseException() is HttpException)
                {
                    HttpException ex = (HttpException)Server.GetLastError().GetBaseException();
                    strErrType += string.Format(SinoPac.WebExpress.Common.Properties.Resources.Msg_ErrorType, ex.GetType().Name);
                    strErrType += " " + string.Format(SinoPac.WebExpress.Common.Properties.Resources.Msg_ErrorCode, ex.GetHttpCode());
                    strErrMsg  += ex.Message.ToString();
                }
            }

            //Exception
            if (string.IsNullOrEmpty(strErrType))
            {
                Exception ex = (Exception)Server.GetLastError().GetBaseException();
                strErrType += string.Format(SinoPac.WebExpress.Common.Properties.Resources.Msg_ErrorType, ex.GetType().Name);
                strErrMsg  += ex.Message.ToString();
            }

            labErrType.Text = Util.getHtmlMessage(Util.HtmlMessageKind.Error, strErrType);
            labErrMsg.Text  = string.Format("<div class='Util_Frame' style='padding:10px;background-color: #ccc;'>{0}</div>", strErrMsg);
        }
    }