1
hutongqing
2025-01-24 2aef482fa7431fb47eef94081ff23ec220f89820
WIDESEAWCS_Server/WIDESEAWCS_Core/Middlewares/ApiLogMiddleware.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -21,17 +22,30 @@
        /// 
        /// </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)
            {
@@ -63,7 +77,7 @@
                    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)