public void Insert() { var result = _httpLogService.InsertAsync(new HttpLog { Duration = 1, Method = "1", ReqestedAt = DateTime.Now, ResponsedAt = DateTime.Now }, 10000).Result; Assert.IsTrue(result > 0); }
public async Task InvokeAsync(HttpContext context) { if (AppSettings.MongoLogging) { var ip = context.Connection.RemoteIpAddress.ToString(); var url = $"{context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}"; var requestedAt = DateTime.Now; var stopWatch = new Stopwatch(); //try { var response = string.Empty; stopWatch.Start(); var originalBodyStream = context.Response.Body; using (var responseBody = new MemoryStream()) { context.Response.Body = responseBody; await _requestDelegate(context); response = await FormatResponse(context.Response); await responseBody.CopyToAsync(originalBodyStream); } stopWatch.Stop(); var model = new HttpLog { IP = ip, URL = url, Method = context.Request.Method, RequsetHeader = (from t in context.Request.Headers select t).ToDictionary(x => x.Key, x => x.Value.ToArray()), ReqestedAt = requestedAt, Request = (await FormatRequest(context.Request)).Replace("\n\t", string.Empty), ResponseHeader = (from t in context.Response.Headers select t).ToDictionary(x => x.Key, x => x.Value.ToArray()), ResponsedAt = DateTime.Now, Response = response, Duration = stopWatch.ElapsedMilliseconds }; await _httpLogService.InsertAsync(model, 5000); //} //catch (Exception ex) { // await _exceptionService.InsertAsync(ex, url, ip); //} } if (AppSettings.FileLogging) { } await _requestDelegate(context); }