forked from mtusi2026/mtusi2026lab4
26 lines
698 B
C#
26 lines
698 B
C#
namespace Messenger.Api.Middleware;
|
|
|
|
public sealed class RequestLoggingMiddleware
|
|
{
|
|
private readonly RequestDelegate _next;
|
|
|
|
public RequestLoggingMiddleware(RequestDelegate next) => _next = next;
|
|
|
|
public async Task InvokeAsync(HttpContext context)
|
|
{
|
|
var logger = context.RequestServices
|
|
.GetRequiredService<ILoggerFactory>()
|
|
.CreateLogger("Http");
|
|
|
|
await _next(context);
|
|
|
|
logger.LogInformation(
|
|
"{Method} {Path} -> {StatusCode} request_id={RequestId}",
|
|
context.Request.Method,
|
|
context.Request.Path,
|
|
context.Response.StatusCode,
|
|
context.Items["RequestId"]
|
|
);
|
|
}
|
|
}
|