private async Task WriteExceptionAsync(HttpContext context, Exception e) { if (e is UnauthorizedAccessException) { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; } else if (e is Exception) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; } context.Response.ContentType = "application/json"; await context.Response.WriteAsync(new MessageModel(false, $"{e.Message}").ToJson()); Parallel.For(0, 1, s => { ErrorLog errorLog = new ErrorLog() { UserId = user.ID, UserName = user.Name, time = DateTime.Now, url = context.Request.Path.ToString(), errorstack = e.StackTrace, errormsg = e.Message }; errorLogServices.Add(errorLog); }); }
public async Task <MessageModel> Add(ErrorLog model) { model.Id = 0; return(new MessageModel(await _ErrorLogServices.Add(model) > 0)); }