From 205fda9480652d4a52c0f035536db1a1dfcee5fa Mon Sep 17 00:00:00 2001 From: "qianhao.xu" Date: Wed, 18 Dec 2024 16:49:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=8E=A7=E5=88=B6=E5=8F=B0=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E8=AF=B7=E6=B1=82=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DOAN.Admin.WebApi/Program.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/DOAN.Admin.WebApi/Program.cs b/DOAN.Admin.WebApi/Program.cs index f48cad0..49f1862 100644 --- a/DOAN.Admin.WebApi/Program.cs +++ b/DOAN.Admin.WebApi/Program.cs @@ -100,6 +100,18 @@ if (app.Environment.IsDevelopment()) workId += 1; } SnowFlakeSingle.WorkId = workId; +//在控制台打印请求信息 +app.Use(async (context, next) => +{ + Console.WriteLine($"Request: {context.Request.Method} {context.Request.Path}"); + + // 调用下一个中间件 + await next(); + + // 如果需要在响应后打印信息,可以在这里进行 + + Console.WriteLine($"Response: {context.Response.StatusCode}"); +}); //使用全局异常中间件 app.UseMiddleware();