chore: 提交现有修改
This commit is contained in:
@@ -9,29 +9,21 @@ namespace TakeoutSaaS.Shared.Web.Middleware;
|
||||
/// <summary>
|
||||
/// 基础请求日志(方法、路径、耗时、状态码、TraceId)。
|
||||
/// </summary>
|
||||
public sealed class RequestLoggingMiddleware
|
||||
public sealed class RequestLoggingMiddleware(RequestDelegate next, ILogger<RequestLoggingMiddleware> logger)
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly ILogger<RequestLoggingMiddleware> _logger;
|
||||
|
||||
public RequestLoggingMiddleware(RequestDelegate next, ILogger<RequestLoggingMiddleware> logger)
|
||||
{
|
||||
_next = next;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
try
|
||||
{
|
||||
await _next(context);
|
||||
await next(context);
|
||||
}
|
||||
finally
|
||||
{
|
||||
stopwatch.Stop();
|
||||
var traceId = TraceContext.TraceId ?? context.TraceIdentifier;
|
||||
_logger.LogInformation(
|
||||
logger.LogInformation(
|
||||
"HTTP {Method} {Path} => {StatusCode} ({Elapsed} ms) TraceId:{TraceId}",
|
||||
context.Request.Method,
|
||||
context.Request.Path,
|
||||
|
||||
Reference in New Issue
Block a user