Реализовать лабораторную работу 3
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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"]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user