| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Text; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | |
| | | /// |
| | | /// </summary> |
| | | private readonly RequestDelegate _next; |
| | | private readonly ILogger<ApiLogMiddleware> _logger; |
| | | |
| | | public ApiLogMiddleware(RequestDelegate next, ILogger<ApiLogMiddleware> logger) |
| | | { |
| | | _next = next; |
| | | _logger = logger; |
| | | } |
| | | |
| | | //todo |
| | | public async Task InvokeAsync(HttpContext context) |
| | | { |
| | | if (App.ExpDateTime != null && (DateTime.Now - App.ExpDateTime.GetValueOrDefault()).TotalSeconds > 0) |
| | | { |
| | | context.Response.StatusCode = HttpStatusCode.InternalServerError.ObjToInt(); |
| | | context.Response.ContentType = "application/json"; |
| | | |
| | | var json = new WebResponseContent(); |
| | | |
| | | json.Message = HttpStatusCode.InternalServerError.ToString();//错误信息 |
| | | json.Code = 500;//500异常 |
| | | |
| | | StreamWriter streamWriter = new StreamWriter(context.Response.Body); |
| | | await streamWriter.WriteAsync(json.Serialize()); |
| | | return; |
| | | } |
| | | |
| | | // 过滤,只有接口 |
| | | if (context.Request.Path.Value?.Contains("api") ?? false) |
| | | { |
| | |
| | | |
| | | ms.Position = 0; |
| | | await ms.CopyToAsync(originalBody); |
| | | if (!(context.Request.Path.Value?.Contains("Get") ?? false)) |
| | | if (!(context.Request.Path.Value?.Contains("get") ?? true)) |
| | | Logger.Add(requestParam, responseParam); |
| | | } |
| | | catch (Exception ex) |