private static void ErrorLog(string type, Exception ex, string message = "")
        {
            Logger logger     = LogManager.GetCurrentClassLogger();
            string baseString = String.Format("Program Version: \"{0}\" User:\"{1}\"; SystemMessage:\"{2}\"; Source:\"{3}\"; StackTrace:\"{4}\"; Method:\"{5}\"; ", FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion, Settings.Instance.Constant("baseUser"), ex.Message, ex.Source, ex.StackTrace, ex.TargetSite);

            if (!String.IsNullOrWhiteSpace(message))
            {
                baseString += String.Format("UserMessage:\"{0}\"; ", message);
            }

            bool debugDataLevel        = false;
            bool debugDataLevelChanged = false;

            try
            {
                debugDataLevel        = (Settings.Instance.Constant("debugDataLevel") != "false") ? true : false;
                debugDataLevelChanged = true;
            }
            catch (Exception ex1)
            {
                ExceptionDecorator.Warn(ex);

                if (!debugDataLevelChanged)
                {
                    debugDataLevel = false;
                }
            }

            if (debugDataLevel)
            {
                baseString += "Data :";
                foreach (DictionaryEntry de in ex.Data)
                {
                    baseString += String.Format("({0};{1}) ", de.Key, de.Value);
                }
                baseString += "; ";
                if ((ex is ArgumentException) || (ex is ArgumentNullException))
                {
                    baseString += String.Format("ParamName : \"{0}\";", (ex as ArgumentException).ParamName);
                }
            }

            if (Settings.Instance.Constant("EncryptLog") != "false")
            {
                Crypto cryptString = new Crypto();
                baseString = cryptString.encryptStringToString_AES(baseString);
            }

            switch (type)
            {
            case "Fatal":
                logger.Fatal(baseString);
                break;

            case "Error":
                logger.Error(baseString);
                break;

            case "Warn":
                logger.Warn(baseString);
                break;

            default:
                logger.Error(baseString);
                break;
            }

            if (!String.IsNullOrWhiteSpace(message))
            {
                MessageBox.Show(message);
            }
        }
예제 #2
0
        ///
        /// Handles the thread exception.
        ///
        public static void Application_ThreadException(
            object sender, ThreadExceptionEventArgs e)
        {
            if (!(e.Exception is ExceptionWrapper))
            {
                ExceptionDecorator.Error(e.Exception);
            }
            switch ((e.Exception as ExceptionWrapper).type)
            {
            case ExceptionWrapper.ErrorTypes.Error:
            {
                if ((e.Exception as ExceptionWrapper).withMessage)
                {
                    ExceptionDecorator.Error((e.Exception as ExceptionWrapper).ex, (e.Exception as ExceptionWrapper).message);
                }
                else
                {
                    ExceptionDecorator.Error((e.Exception as ExceptionWrapper).ex);
                }
                break;
            };

            case ExceptionWrapper.ErrorTypes.Fatal:
            {
                if ((e.Exception as ExceptionWrapper).withMessage)
                {
                    ExceptionDecorator.Fatal((e.Exception as ExceptionWrapper).ex, (e.Exception as ExceptionWrapper).message);
                }
                else
                {
                    ExceptionDecorator.Fatal((e.Exception as ExceptionWrapper).ex);
                }
                break;
            };

            case ExceptionWrapper.ErrorTypes.Warning:
            {
                if ((e.Exception as ExceptionWrapper).withMessage)
                {
                    ExceptionDecorator.Warn((e.Exception as ExceptionWrapper).ex, (e.Exception as ExceptionWrapper).message);
                }
                else
                {
                    ExceptionDecorator.Warn((e.Exception as ExceptionWrapper).ex);
                }
                break;
            };

            case ExceptionWrapper.ErrorTypes.Info:
            {
                if ((e.Exception as ExceptionWrapper).withMessage)
                {
                    ExceptionDecorator.Info((e.Exception as ExceptionWrapper).comment, (e.Exception as ExceptionWrapper).message, (e.Exception as ExceptionWrapper).data);
                }
                else
                {
                    ExceptionDecorator.Info((e.Exception as ExceptionWrapper).comment, (e.Exception as ExceptionWrapper).data);
                }
                break;
            };

            case ExceptionWrapper.ErrorTypes.Trace:
            {
                ExceptionDecorator.Trace();
                break;
            };

            case ExceptionWrapper.ErrorTypes.Debug:
            {
                ExceptionDecorator.Trace();
                break;
            };

            default:
            {
                if ((e.Exception as ExceptionWrapper).withMessage)
                {
                    ExceptionDecorator.Error((e.Exception as ExceptionWrapper).ex, (e.Exception as ExceptionWrapper).message);
                }
                else
                {
                    ExceptionDecorator.Error((e.Exception as ExceptionWrapper).ex);
                }
                break;
            };
            }
        }
예제 #3
0
 /// <summary>
 /// Information
 /// </summary>
 /// <param name="comment">description</param>
 /// <param name="data">key/value pair of data</param>
 /// <param name="message">MessageBox text</param>
 public static void Info(this Component Control, string comment, string message = "", ICollection <DictionaryEntry> data = null)
 {
     ExceptionDecorator.Info(comment, message, data);
 }