コード例 #1
0
        /// <summary>
        /// Executes an action inside a try catch and logs any exceptions.
        /// </summary>
        /// <param name="errorMessage">Error message to log.</param>
        /// <param name="action">The function to call.</param>
        /// <param name="logger">Logger object.</param>
        /// <returns>Return item.</returns>
        public static BoolMessageItem TryCatchLogGetBoolMessageItem(string errorMessage, Func <BoolMessageItem> action, Action <object, Exception, object[]> logger)
        {
            BoolMessageItem result      = BoolMessageItem.False;
            string          fullMessage = string.Empty;

            try
            {
                result = action();
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger(errorMessage, ex, null);
                }
                else if (_logger != null)
                {
                    _logger.Error(errorMessage, ex, null);
                }

                fullMessage = errorMessage + Environment.NewLine
                              + ex.Message + Environment.NewLine
                              + ex.Source + Environment.NewLine
                              + ex.StackTrace;
                result = new BoolMessageItem(null, false, fullMessage);
            }
            return(result);
        }
コード例 #2
0
ファイル: ExecuteHelper.cs プロジェクト: windygu/Express-SDK
        /// <summary>
        /// Executes an action inside a try catch and logs any exceptions.
        /// </summary>
        /// <param name="action"></param>
        public static BoolMessageItem TryCatchLogGetBoolMessageItem(string errorMsg, Func <BoolMessageItem> action)
        {
            BoolMessageItem result      = BoolMessageItem.False;
            string          fullMessage = string.Empty;

            try
            {
                result = action();
            }
            catch (Exception ex)
            {
                Log4NetBase.Log(errorMsg, ex);
                fullMessage = errorMsg + Environment.NewLine
                              + ex.Message + Environment.NewLine
                              + ex.Source + Environment.NewLine
                              + ex.StackTrace;
                result = new BoolMessageItem(null, false, fullMessage);
            }
            return(result);
        }
コード例 #3
0
 /// <summary>
 /// Convert the result to an exit code.
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 public static int AsExitCode(this BoolMessageItem result)
 {
     return(result.Success ? 0 : 1);
 }