예제 #1
0
        /// <summary>
        /// 监控消耗时间
        /// </summary>
        /// <typeparam name="T">返回类型</typeparam>
        /// <param name="action">执行方法</param>
        /// <param name="dbType">数据库类型</param>
        /// <param name="memberName">调用方法</param>
        /// <param name="dbConnection">数据库连接</param>
        /// <returns>返回值</returns>
        public static T Monitor <T>(Func <T> action, string dbType = null, string memberName = null, IDbConnection dbConnection = null)
        {
            var  beginTime = DateTimeUtil.Now;
            bool isSuccess = true;

            try
            {
                return(action());
            }
            catch (Exception ex)
            {
                LogUtil.Error($"执行的sql方法:{memberName}", _LOGGER_SQL);
                LogUtil.Error(ex);
                throw;
            }
            finally
            {
                var endTime = DateTimeUtil.Now;
                SqlSendUtil.GrabSql(memberName, (endTime - beginTime).TotalMilliseconds, isSuccess, dbType: dbType, dataBaseName: dbConnection?.Database);
            }
        }
예제 #2
0
        /// <summary>
        /// 监控消耗时间
        /// </summary>
        /// <param name="query">SqlQuery</param>
        /// <param name="action">执行方法</param>
        /// <param name="dbType">数据库类型</param>
        /// <param name="dbConnection">数据库连接</param>
        public static void Monitor(SqlQuery query, Action action, string dbType = null, IDbConnection dbConnection = null)
        {
            var  beginTime = DateTimeUtil.Now;
            bool isSuccess = true;

            try
            {
                action();
            }
            catch (Exception ex)
            {
                LogUtil.Error($"执行的sql语句:{query.CommandText}", _LOGGER_SQL);
                LogUtil.Error(ex);
                throw;
            }
            finally
            {
                var endTime = DateTimeUtil.Now;
                SqlSendUtil.GrabSql(query, (endTime - beginTime).TotalMilliseconds, isSuccess, dbType: dbType, dataBaseName: dbConnection?.Database);
            }
        }