using Model.Base; using Service.MonitorLog; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using System; using System.Diagnostics; using System.IO;
namespaceTest { publicstaticclassCustomLoggingMiddleware { publicstaticvoidUseCustomLogging(this IApplicationBuilder app) { app.Use(async (context, next) => { var requestContent = ""; var contentType = context.Request.ContentType; context.Request.EnableBuffering(); // 只接受json格式参数,防止文件流等参数超长 if (!string.IsNullOrWhiteSpace(contentType) && contentType.Contains("json", StringComparison.OrdinalIgnoreCase)) { var requestReader = new StreamReader(context.Request.Body); requestContent = await requestReader.ReadToEndAsync(); } context.Request.Body.Position = 0;