mirror of
https://github.com/MikuLeaks/KianaBH3.git
synced 2025-12-12 13:04:33 +01:00
34 lines
886 B
C#
34 lines
886 B
C#
using KianaBH.Util;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace KianaBH.SdkServer.Utils;
|
|
|
|
public class RequestLoggingMiddleware(RequestDelegate next)
|
|
{
|
|
public async Task InvokeAsync(HttpContext context, Logger logger)
|
|
{
|
|
var request = context.Request;
|
|
var method = request.Method;
|
|
var path = request.Path + request.QueryString;
|
|
|
|
await next(context);
|
|
|
|
var statusCode = context.Response.StatusCode;
|
|
|
|
if (path.StartsWith("/report") || path.Contains("/log/") || path == "/alive")
|
|
return;
|
|
|
|
if (statusCode == 200)
|
|
{
|
|
logger.Info($"{method} {path} => {statusCode}");
|
|
}
|
|
else if (statusCode == 404)
|
|
{
|
|
logger.Warn($"{method} {path} => {statusCode}");
|
|
}
|
|
else
|
|
{
|
|
logger.Error($"{method} {path} => {statusCode}");
|
|
}
|
|
}
|
|
} |