/// <summary> /// 自动记录错误日志, 记录退出返回日志。 /// 因此,调用该方法应该直接Return,防止在调用后又执行代码。 /// </summary> async Task <ContentResult> Error(int code, string message, string task, int instanceId, EsbOperation period, string invokedUrl = "") { var log = EsbLog.Create(task, EsbLogLevel.Failure, period, HttpContext.Connection.RemoteIpAddress.ToString(), instanceId, message, invokedUrl); _esbModelContext.Add(log); await _esbModelContext.SaveChangesAsync(); ResponseBody response = new ResponseBody(code, message, "", SimpleRESTfulReturn.Empty); await LogEnd(task, instanceId, invokedUrl, message.Length + 4); return(Content(response.Value)); }
public static EsbLog Create(string taskIdentity, EsbLogLevel level, EsbOperation operation, string fromIp, int instanceId, string message, string invokedUrl = "", int inLength = 0, int outLength = 0) { var log = new EsbLog { TaskIdentity = taskIdentity, CreatedOn = DateTime.Now, FromIP = fromIp, InstanceID = instanceId, InvokedUrl = invokedUrl, LogLevel = level, Message = message, Operation = operation, RequestLength = inLength, ResponseLength = outLength }; return(log); }