All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 24s
Docker Build & Deploy / Deploy to Production (push) Successful in 6s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 2s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s
1. 新增 BudgetStatsService:将预算统计逻辑从 BudgetService 中提取为独立服务,支持月度和年度统计,包含归档数据支持和硬性预算调整算法 2. 日志系统增强:添加请求ID追踪功能,支持通过请求ID查询关联日志,新增类名筛选功能 3. 日志解析优化:修复类名解析逻辑,正确提取 SourceContext 中的类名信息 4. 代码清理:移除不需要的方法名相关代码,简化日志筛选逻辑
38 lines
926 B
C#
38 lines
926 B
C#
using Serilog.Context;
|
|
|
|
namespace WebApi.Middleware;
|
|
|
|
public class RequestIdMiddleware
|
|
{
|
|
private readonly RequestDelegate _next;
|
|
|
|
public RequestIdMiddleware(RequestDelegate next)
|
|
{
|
|
_next = next;
|
|
}
|
|
|
|
public async Task InvokeAsync(HttpContext context)
|
|
{
|
|
var requestId = context.Request.Headers["X-Request-ID"].FirstOrDefault() ?? Guid.NewGuid().ToString("N");
|
|
|
|
context.Items["RequestId"] = requestId;
|
|
|
|
using (LogContext.PushProperty("RequestId", requestId))
|
|
{
|
|
await _next(context);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class RequestIdExtensions
|
|
{
|
|
public static string? GetRequestId(this HttpContext context)
|
|
{
|
|
return context.Items["RequestId"] as string;
|
|
}
|
|
|
|
public static IApplicationBuilder UseRequestId(this IApplicationBuilder builder)
|
|
{
|
|
return builder.UseMiddleware<RequestIdMiddleware>();
|
|
}
|
|
} |