/// <summary> /// 调用WCF /// </summary> /// <param name="data"></param> /// <returns></returns> static void WriteLog2WCF(BizLogModel data) { using (APIClient client = new APIClient()) { client.WriteLog(data); } }
/// <summary> /// 写业务日志 /// </summary> public static void WriteLog(BizLog log) { if (log == null) { return; } string info = string.Empty; try { BizLogModel model = Map(log); info = Check(model); if (string.IsNullOrEmpty(info)) { WriteLog2WCF(model); return; } } catch (Exception ex) { var exReal = ex.InnerException == null ? ex : ex.InnerException; info = exReal.ToString(); } if (string.IsNullOrEmpty(info)) { #if DEBUG throw new BusinessLogicException(info); #else Log.Error(string.Format("写[业务日志]出错,<br/>原因:{0},<br/>日志数据:{1}." , info , JsonConvert.SerializeObject(log))); #endif } }
/// <summary> /// 验证日志是否合法 /// </summary> /// <param name="log"></param> /// <returns></returns> static string Check(BizLogModel log) { if (log == null) { return("[业务日志]不能为空!"); } if (!string.IsNullOrWhiteSpace(log.Keyword) && log.KeywordTypeID <= 0) { return("如果您输入[关键词],需要同时输入[关键词类型]!"); } if (!string.IsNullOrWhiteSpace(log.UserCode) && log.UserType <= 0) { return("如果您输入[用户编码],需要同时输入[用户类型]!"); } if (string.IsNullOrWhiteSpace(log.SystemCode)) { return("[系统编码]不能为空!"); } if (string.IsNullOrWhiteSpace(log.ModuleName)) { return("[模块名称]不能为空!"); } if (string.IsNullOrWhiteSpace(log.Summary)) { return("[日志摘]要不能为空!"); } return(string.Empty); }
public static PagedList <BizLogModel> QueryBizLogInfo(BizLog log, int pageIndex, int pageSize, DateTime?startTime, DateTime?endTime, out int totalRecords) { BizLogModel[] getData = new BizLogModel[] {}; using (APIClient client = new APIClient()) { getData = client.QueryLog(out totalRecords, new BizLogFilter() { PageIndex = pageIndex, PageSize = pageSize, Keyword = log.Keyword, KeywordTypeID = (int)log.KeywordType, Summary = log.Summary, SystemCode = GetSystemType.GetSystemTypeCode(log.SystemCode), ModuleName = log.ModuleName, UserRealName = log.UserRealName, CreateOnStart = startTime, CreateOnEnd = endTime }); } return(getData.ToPagedList(pageIndex, pageSize)); }
/// <summary> /// Mapping /// </summary> /// <param name="log"></param> /// <returns></returns> static BizLogModel Map(BizLog log) { if (log == null) { return(null); } BizLogModel data = new BizLogModel(); data.CreateOn = DateTime.Now; //统一处理 data.Details = log.Details; data.IP = log.IP; data.Keyword = log.Keyword; data.KeywordTypeID = (int)log.KeywordType; data.Mac = log.Mac; data.ModuleName = log.ModuleName; data.Summary = log.Summary; data.SystemCode = GetSystemType.GetSystemTypeCode(log.SystemCode); //系统 data.URL = log.URL; data.UserCode = log.UserCode; data.UserRealName = log.UserRealName; data.UserType = (int)log.UserType; return(data); }