/// <summary> /// 创建运行日志信息 /// </summary> /// <param name="runtimeLogModel">运行日志</param> /// <returns>运行日志信息</returns> public async Task <RuntimeLogInfo> CreateAsync(RuntimeLogModel runtimeLogModel) { runtimeLogModel.NotNull("运行日志不能为空"); var runtimeLogInfo = new RuntimeLogInfo { FCallMemberName = runtimeLogModel.FCallMemberName, FContent = runtimeLogModel.FContent, FCreateTime = DateTimeUtil.Now, FExecuteTime = runtimeLogModel.FExecuteTime, FIsDeleted = false, FLogLevel = runtimeLogModel.FLogLevel, FProjectName = runtimeLogModel.FProjectName, FServicerMac = runtimeLogModel.FServerMac, FSource = runtimeLogModel.FSource, FRequestGuid = runtimeLogModel.FRequestGuid }; if (runtimeLogInfo.FProjectName.IsNotNullAndNotEmptyWhiteSpace()) { runtimeLogInfo.FProjectID = await _projectDomainService.GetProjectIDAsync(runtimeLogInfo.FProjectName); } if (runtimeLogInfo.FServicerMac.IsNotNullAndNotEmptyWhiteSpace()) { runtimeLogInfo.FServicerID = await _servicerDomainService.GetServerIDAsync(runtimeLogInfo.FServicerMac); } return(runtimeLogInfo); }
/// <summary> /// 创建警告提示信息 /// </summary> /// <param name="runtimeLogInfo">运行日志信息</param> /// <returns>警告提示信息</returns> public WarningLogInfo Create(RuntimeLogInfo runtimeLogInfo) { return(new WarningLogInfo { FCreateTime = DateTimeUtil.Now, FCreateUserID = -1, FDealState = DealState.WaitDeal, FIsDeleted = false, FNoticeState = NoticeState.WaitNotice, FRunTimeLogID = runtimeLogInfo.FID, FLogSign = runtimeLogInfo.GetSafeHashID() }); }
/// <summary> /// 分析日志 /// </summary> /// <param name="runtimeLogInfo">运行日志</param> /// <returns></returns> public async Task AnalysisLogAsync(RuntimeLogInfo runtimeLogInfo) { if (runtimeLogInfo != null && runtimeLogInfo.IsNeedWarning()) { var warningLogInfo = _warningLogDomainService.Create(runtimeLogInfo); //判断一小时之内有没有超出五条同样日志标识的记录,假如超出则不发送邮件, int waitDealCount = await _warningLogRepository.QueryCountAsync(m => m.FLogSign == warningLogInfo.FLogSign && m.FCreateTime >= DateTimeUtil.Now.AddHours(-1) && m.FNoticeState == NoticeState.WaitNotice && m.FIsDeleted == false); if (waitDealCount <= 5) { //发送邮件 await _emailSendedRecordDomainService.SendEmailAsync($"你有来自项目【{runtimeLogInfo.FProjectName}】新的警告邮件", runtimeLogInfo.FContent, runtimeLogInfo.FProjectID); warningLogInfo.FNoticeState = NoticeState.Noticed; } await _warningLogRepository.InsertOneAsync(warningLogInfo, keyName : "FID", ignoreFields : FID); } }