void LogInteraction(string _name, string _class) { InteractionLog log = null; if (interactionLogs != null) { log = new InteractionLog(); log.interactiveName = _name; log.interactiveClass = _class; } if (!inCarriage) { if (interactionLogs != null) { interactionLogs.Add(log); } } else { if (log != null) { //pointController._steering.OnArrival += (_) => { interactionLogs.Add(log); }; } else { } } }
public async Task <IActionResult> Edit(int id, [Bind("Event,Timestamp,Description,WebinarMeetingId,Id,Modified")] InteractionLog interactionLog) { if (id != interactionLog.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(interactionLog); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InteractionLogExists(interactionLog.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(interactionLog)); }
public async Task <IActionResult> Create([Bind("Event,Timestamp,Description,WebinarMeetingId,Id,Modified")] InteractionLog interactionLog) { if (ModelState.IsValid) { _context.Add(interactionLog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(interactionLog)); }
/// <summary> /// 转换日志记录对象的为字符串形式 /// </summary> /// <param name="interactionLog">日志记录</param> /// <returns></returns> public static string GetInteractionLogInfo(InteractionLog interactionLog) { StringBuilder interactionLogInfo = new StringBuilder(); foreach (var property in interactionLog.GetType().GetProperties()) { // 两个 { 或者 } 连写表示单个 interactionLogInfo.AppendFormat("{0}: {{{1}}}; ", property.Name, property.GetValue(interactionLog, null) == null ? "null" : property.GetValue(interactionLog, null)); } // 移除字符串尾部的 ' ' ';' 字符 return(interactionLogInfo.ToString().TrimEnd(' ', ';')); }
/// <summary> /// 通用日志处理逻辑 /// </summary> /// <param name="invocation"></param> /// <param name="returnValue"></param> /// <param name="succeed"></param> /// <param name="invokedTime"></param> /// <param name="elapsedTime"></param> /// <param name="exception"></param> /// <returns></returns> private object ProcessBusin(IMethodInvocation invocation, object returnValue, bool succeed, DateTime invokedTime, double elapsedTime, Exception exception) { // 判断返回类型是否为ResultInfo<T> bool isResultInfo = default(bool); if (invocation.Method.ReturnType.Name.Equals(LogUtil.ResultInfoTypeName)) { isResultInfo = true; } // 如果方法发生异常(returnValue为null)且返回对象的类型是 ResultInfo // 或者方法没有异常(返回结果为null)且返回对象的类型是 ResultInfo if (((returnValue == null && !succeed) && isResultInfo) || (returnValue == null && succeed && isResultInfo)) { // 初始化返回值对象 returnValue = Activator.CreateInstance(invocation.Method.ReturnType); } PropertyInfo piSucceed = null; PropertyInfo piMessage = null; PropertyInfo piResult = null; if (isResultInfo) { #region 通过反射解析对象属性 piSucceed = invocation.Method.ReturnType.GetProperty("Succeed"); piMessage = invocation.Method.ReturnType.GetProperty("Message"); piResult = invocation.Method.ReturnType.GetProperty("Result"); // 执行异常时,设置对应的属性值 // 设置返回值的Succeed属性为false, Message属性为异常信息 if (!succeed) { if (piSucceed != null) { piSucceed.SetValue(returnValue, false, null); } if (piMessage != null) { piMessage.SetValue(returnValue, TooltipMessages.ExceptionOccur, null); } // 如果结果是bool值,则将结果设置为false if (piResult != null && piResult.GetType() == typeof(bool)) { piResult.SetValue(returnValue, false, null); } } #endregion } // 创建日志记录对象 InteractionLog log = new InteractionLog(); log.Succeed = succeed; log.InvokedTime = invokedTime; log.ElapsedTime = elapsedTime.ToString(); log.Operation = LogUtil.GetOperation(invocation); log.InvokedAddress = LogUtil.GetInvokedAddress(); log.Arguments = LogUtil.GetArgument(invocation); log.Message = isResultInfo ? LogUtil.GetMessage(returnValue, succeed, piMessage, exception) : LogUtil.GetMessage(succeed, exception); log.Result = isResultInfo ? LogUtil.GetResult(returnValue, piResult) : LogUtil.GetResult(invocation, returnValue, succeed); // 记录日志信息 // 两种选择 1 写数据库 2 写文本文件 此处选择写文本文件 string interactionLogInfo = LogUtil.GetInteractionLogInfo(log); logger.Info(interactionLogInfo); return(returnValue); }