示例#1
0
        /// <summary>
        ///     Get exception message and write to log file
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="messageError"></param>
        /// <param name="errorType"></param>
        /// <returns></returns>
        public static string GetExceptionMessage(this Exception ex, string messageError, CLErrorType errorType)
        {
            var strBuilder = new StringBuilder();
            strBuilder.AppendLine("<Exception details>");
            strBuilder.AppendLine("We have detected an exception. Message output start");
            strBuilder.AppendLine("[Date and time of occurrence]");
            strBuilder.AppendLine("[" + DateTime.Now.ToString(Constants.DateFormat.DateWithTime) + "]");
            strBuilder.AppendLine("[Message content]");
            strBuilder.AppendLine(messageError);
            strBuilder.AppendLine("[Exceptions level]");
            strBuilder.AppendLine(GetErrorTypeText(errorType));
            strBuilder.AppendLine("[Stack on the internal exception]");
            strBuilder.AppendLine("[Exception class]      " + ex.GetType());
            strBuilder.AppendLine("[Exception message]    " + ex.Message);
            strBuilder.AppendLine("[Exception stack trace]" + ex.StackTrace);

            //Get InnerException Message
            if (ex.InnerException != null)
            {
                strBuilder.AppendLine();
                strBuilder.AppendLine("[It outputs the exception that was detected by the internal.]");
                strBuilder.AppendLine("[Exception class]      " + ex.InnerException.GetType());
                strBuilder.AppendLine("[Exception message]    " + ex.InnerException.Message);
                strBuilder.AppendLine("[Exception stack trace]" + ex.InnerException.StackTrace);
            }

            strBuilder.AppendLine("</Exception details>");
            strBuilder.AppendLine();

            //return exception info
            return strBuilder.ToString();
        }
示例#2
0
 /// <summary>
 ///     Initialize for VST generic exception with inner exception
 /// </summary>
 /// <param name="innerException"></param>
 /// <param name="errorCode"></param>
 /// <param name="parammeters"></param>
 public CLException(Exception innerException, String errorCode, CLErrorType errorType, params object[] parammeters)
     : base(String.Empty, innerException)
 {
     this.ErrorCode = errorCode;
     this.ErrorType = errorType;
     this._params = parammeters;
 }
 /// <summary>
 ///     Initialize for VST business exception
 /// </summary>
 /// <param name="errorCode"></param>
 /// <param name="errorType"></param>
 /// <param name="parammeters"></param>
 public CLBusinessException(string errorCode, CLErrorType errorType, params object[] parammeters)
     : base(errorCode, errorType, parammeters)
 {
     Parammeters = parammeters;
     if (errorType == CLErrorType.Error)
     {
         //Log error
         var errorMsg = string.Format(errorCode, parammeters);
         Framework.Logger.Provider.Instance.LogError(this.GetExceptionMessage(errorMsg, CLErrorType.Error));
     }
 }
示例#4
0
        private static string GetErrorTypeText(CLErrorType errorType)
        {
            //Get level of exception
            switch (errorType)
            {
                case CLErrorType.Error:
                    return Constants.CLLogConstants.Error;

                case CLErrorType.Warn:
                    return Constants.CLLogConstants.Warn;

                case CLErrorType.Info:
                    return Constants.CLLogConstants.Info;
            }
            return string.Empty;
        }
示例#5
0
 public ErrorModel(CLErrorType type, string code)
 {
     Type = type;
     Code = code;
     Message = code;
 }
示例#6
0
 /// <summary>
 /// Initialize for VST generic exception
 /// </summary>
 /// <param name="errorCode"></param>
 /// <param name="parammeters"></param>
 public CLException(String errorCode, CLErrorType errorType, params object[] parammeters)
 {
     this.ErrorCode = errorCode;
     this.ErrorType = errorType;
     this._params = parammeters;
 }