1
wangxinhui
2025-01-16 5ab6b36c0c4bd80a31dcdd9f15cc835b7352c4e7
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -31,6 +32,21 @@
        //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)
            {
@@ -84,28 +100,37 @@
        private string RequestDataLog(HttpContext context)
        {
            var request = context.Request;
            if (request.ContentType?.ToLower() != "multipart/form-data" && request.ContentLength <= 100000)
            {
                var sr = new StreamReader(request.Body);
                object obj = new
            var sr = new StreamReader(request.Body);
            object obj;
            string bodyData = sr.ReadToEndAsync().Result;
            if (request.ContentLength <= 100000)
            {
                obj = new
                {
                    QueryString = request.QueryString.ToString(),
                    BodyData = sr.ReadToEndAsync().Result
                    BodyData = bodyData
                };
                string data = JsonConvert.SerializeObject(obj);
                request.Body.Position = 0;
                return data;
            }
            return "";
            else
            {
                obj = new
                {
                    QueryString = request.QueryString.ToString(),
                    BodyData = ""
                };
            }
            string data = JsonConvert.SerializeObject(obj);
            request.Body.Position = 0;
            return data; ;
        }
        private string ResponseDataLog(HttpResponse response)
        {
            if (response.ContentType?.ToLower() != "multipart/form-data" && response.ContentLength <= 100000)
            if (response.ContentLength <= 100000)
            {
                response.Body.Position = 0;
                using StreamReader stream = new StreamReader(response.Body, leaveOpen: true);