public async Task <IResponseEntity> CreateAsync(OprationLogAddRequest req) { var entity = _mapper.Map <SysOperationLogEntity>(req); var item = await _oprationLogRepository.InsertAsync(entity); return(ResponseEntity.Result(item?.Id != "")); }
public async Task LogAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var sw = new Stopwatch(); sw.Start(); dynamic actionResult = (await next()).Result; sw.Stop(); //操作参数 var args = JsonConvert.SerializeObject(context.ActionArguments, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); //操作结果 var result = JsonConvert.SerializeObject(actionResult?.Value, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var res = actionResult?.Value as IResponseEntity; string ua = _accessor.HttpContext.Request.Headers["User-Agent"]; var client = UAParser.Parser.GetDefault().Parse(ua); var device = client.Device.Family; var title = GetCurrentActionDesc(context); var apiPath = GetCurrentRoutePath(context); var apiMethod = context.HttpContext.Request.Method.ToLower(); var ip = IPHelper.GetIP(_accessor?.HttpContext?.Request); var req = new OprationLogAddRequest { ApiTitle = title, ApiPath = apiPath, ApiMethod = apiMethod, ElapsedMilliseconds = sw.ElapsedMilliseconds, Status = res.Success, Message = res.Message, Browser = client.UA.Family, Os = client.OS.Family, Device = device.ToLower() == "other" ? "" : device, BrowserInfo = ua, Ip = ip, RealName = _authUser.DisplayName, Params = args, Result = result == null?"": result }; await _oprationLogService.CreateAsync(req); }