/// <summary> /// Async add log. /// </summary> /// <param name="newLogInfo"></param> /// <returns></returns> public Task <int> AddLogInfoAsync(ErrorInfoLogModel newLogInfo) { var searchSql = $@"INSERT INTO {DataTableGlobal.Chooseloginfo} ( ContentType, ErrorMessage, InnerErrorMessage, ErrorTypeFullName, StackTrace, ErrorTime, ErrorType ) VALUES ( @ContentType, @ErrorMessage, @InnerErrorMessage, @ErrorTypeFullName, @StackTrace, @ErrorTime, @ErrorType )" ; var param = new DynamicParameters(newLogInfo); var userId = SqlHelper.ExcuteNonQueryAsync(searchSql, param); return(userId); }
/// <summary> /// Add log /// </summary> /// <param name="newLogInfo"></param> /// <returns></returns> public int AddLogInfo(ErrorInfoLogModel newLogInfo) { if (newLogInfo == null) { return(0); } var searchSql = @"INSERT INTO piferrorlog( ContentType, ErrorMessage, InnerErrorMessage, ErrorTypeFullName, StackTrace, ErrorTime, ErrorType ) VALUES ( @ContentType, @ErrorMessage, @InnerErrorMessage, @ErrorTypeFullName, @StackTrace, @ErrorTime, @ErrorType )"; var param = new DynamicParameters(newLogInfo); var userId = SqlHelper.ExcuteNonQuery(searchSql, param); return(userId); }
/// <summary> /// write log info to redis /// </summary> /// <param name="errorModel">log info.</param> /// <returns></returns> private Task <long> WriteAllLogToRedis(ErrorInfoLogModel errorModel) { var cachKey = AppConfigurationHelper.GetAppSettings <CacheLogModel>("AppSettings:ErrorLogCache"); cachKey = string.IsNullOrEmpty(cachKey?.Cachekey) ? new CacheLogModel { Cachekey = "ErrorLogCache", DatabaseNumber = 1 } : cachKey; var addTask = RedisCacheHelper.AddListAsync(cachKey.Cachekey, errorModel, cachKey.DatabaseNumber); return(addTask); }
/// <summary> /// write error info. /// </summary> /// <param name="exception"></param> /// <param name="context"></param> public Task <int> WriteErrorInfo(Exception exception, HttpContext context = null) { var errorModel = new ErrorInfoLogModel { ContentType = context == null ? "" : (string)context.Request?.Headers["Accept"], ErrorMessage = exception?.Message, ErrorTime = DateTime.Now, ErrorTypeFullName = exception?.GetType().FullName, InnerErrorMessage = exception?.InnerException?.Message, StackTrace = exception?.StackTrace, ErrorType = ErrorTypeEnum.Error.GetHashCode() }; var resulte = StockErrorLogInfo(errorModel); return(resulte); }
/// <summary> /// write warning. /// </summary> /// <param name="warningString">warning string</param> /// <returns></returns> public Task <long> WriteWarningInfo(string warningString) { var errorModel = new ErrorInfoLogModel { ContentType = "程序警告", ErrorMessage = warningString, ErrorTime = DateTime.Now, ErrorTypeFullName = "警告", InnerErrorMessage = warningString, StackTrace = "", ErrorType = ErrorTypeEnum.Warning.GetHashCode() }; var resulte = WriteAllLogToRedis(errorModel); if (resulte.Result > 0) { StockErrorLogInfo(); } return(resulte); }
/// <summary> /// Stock method /// </summary> /// <param name="cacheModel"></param> private Task <int> StockErrorLogInfo(ErrorInfoLogModel cacheModel) { var logInfoDataAccess = new LogInfoDataAccess(); return(logInfoDataAccess.AddLogInfoAsync(cacheModel)); }