Пример #1
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0}: {1}", this.ErrorType, this.Message);

            ErrorItem innerError = this.InnerError;

            while (innerError != null)
            {
                sb.AppendFormat(" ---> {0}: {1}", innerError.ErrorType, innerError.Message);
                innerError = innerError.InnerError;
            }
            sb.Append("\r\n" + this.FramesToString());
            return(sb.ToString());
        }
        /// <summary>
        /// Generates a unique key based on the error. The key will be an MD5 hask of the type, type code, and method.
        /// </summary>
        /// <param name="errorItem">The error item</param>
        /// <returns>The unique key for the error</returns>
        private string GetUniqueKey(ErrorItem errorItem)
        {
            string type = errorItem.ErrorType;
            string typeCode = errorItem.ErrorTypeCode;
            string method = errorItem.SourceMethod;

            string uniqueKey = string.Format("{0}-{1}-{2}", type ?? "", typeCode ?? "", method ?? "");

            return uniqueKey.ToMD5Hash();
        }
Пример #3
0
        public ErrorItem(Exception ex)
        {
            try
            {
                var keys = ex.Data.Keys;
                Data = new Dictionary <string, string>();

                foreach (var item in keys)
                {
                    if (ex.Data[item] != null)
                    {
                        Data.Add(item.ToString(), ex.Data[item].ToString());
                    }
                }

                Message = ex.Message;

#if NETFULL
                if (ex is System.Data.SqlClient.SqlException)
                {
                    System.Data.SqlClient.SqlException sql = ex as System.Data.SqlClient.SqlException;

                    if (sql.Errors.Count > 0 && sql.Errors[0].Number != 0)
                    {
                        ErrorTypeCode = sql.Errors[0].Number.ToString();
                        if (!string.IsNullOrEmpty(sql.Errors[0].Server))
                        {
                            Message = Message + "\r\nServer: " + sql.Errors[0].Server;
                        }
                    }
                    else
                    {
                        ErrorTypeCode = Marshal.GetHRForException(ex).ToString();
                    }
                }
                else
                {
                    ErrorTypeCode = Marshal.GetHRForException(ex).ToString();
                }
#endif

                //this is the default HResult. Ignore it?
                //Leave it since we are already using it. Would cause unique errors to reset on people
                //if (!string.IsNullOrEmpty(ErrorTypeCode) && ErrorTypeCode == "-2146233088")
                //{
                //    ErrorTypeCode = "";
                //}

                var t = ex.GetType();

                ErrorType = t.FullName;

                if (ex is StringException)
                {
                    AddTraceFrames((StringException)ex);
                }
                else
                {
                    AddTraceFrames(ex);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            if (ex.InnerException != null)
            {
                InnerError = new ErrorItem(ex.InnerException);
            }
        }
Пример #4
0
        public ErrorItem(Exception ex)
        {
            try
            {
                var keys = ex.Data.Keys;
                Data = new Dictionary<string, string>();

                foreach (var item in keys)
                {
                    if (ex.Data[item] != null)
                    {
                        Data.Add(item.ToString(), ex.Data[item].ToString());
                    }
                }

                Message = ex.Message;

                if (ex is System.Data.SqlClient.SqlException)
                {
                    System.Data.SqlClient.SqlException sql = ex as System.Data.SqlClient.SqlException;

                    if (sql.Errors.Count > 0 && sql.Errors[0].Number != 0)
                    {
                        ErrorTypeCode = sql.Errors[0].Number.ToString();
                        if (!string.IsNullOrEmpty(sql.Errors[0].Server))
                        {
                            Message = Message + "\r\nServer: " + sql.Errors[0].Server;
                        }
                    }
                    else
                    {
                        ErrorTypeCode = Marshal.GetHRForException(ex).ToString();
                    }
                }
                else
                {
                    ErrorTypeCode = Marshal.GetHRForException(ex).ToString();
                }

                //this is the default HResult. Ignore it?
                //Leave it since we are already using it. Would cause unique errors to reset on people
                //if (!string.IsNullOrEmpty(ErrorTypeCode) && ErrorTypeCode == "-2146233088")
                //{
                //    ErrorTypeCode = "";
                //}

                var t = ex.GetType();

                ErrorType = t.FullName;

                if (ex is StringException)
                {
                    AddTraceFrames((StringException)ex);
                }
                else
                {
                    AddTraceFrames(ex);
                }

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            if (ex.InnerException != null)
            {
                InnerError = new ErrorItem(ex.InnerException);
            }
        }