refactor: ♻️ 异常请求输出追踪标识

This commit is contained in:
tk 2024-12-19 10:10:19 +08:00 committed by nsnail
parent 93fe9e41b7
commit ce697588f5
9 changed files with 17 additions and 12 deletions

View File

@ -128,8 +128,8 @@
请求方式
请求日志导出
调试
踪标识
踪标识
身份证
运行
通知

@ -1 +1 @@
Subproject commit 89586fd0c666cb907cb24690498c3211e578483f
Subproject commit b7b73bbd298a5376eef8e250761760e9b4441eb0

@ -1 +1 @@
Subproject commit c851ae3da25abd26364b0965d6d6affc76abee9f
Subproject commit 433c4ee94c0d19ed98d1713885cd60bad3424c5f

View File

@ -100,7 +100,7 @@ public record Sys_RequestLog : SimpleEntity, IFieldCreatedTime, IFieldOwner, IFi
public virtual long? OwnerId { get; init; }
/// <summary>
/// 请求踪标识
/// 请求踪标识
/// </summary>
[Column]
[CsvIgnore]

View File

@ -22,4 +22,9 @@ public record RestfulInfo<T> : DataAbstraction
/// </summary>
/// <example>请求成功</example>
public object Msg { get; init; }
/// <summary>
/// 追踪标识
/// </summary>
public Guid? TraceId { get; set; }
}

View File

@ -76,6 +76,6 @@ public sealed record ExportRequestLogRsp : QueryRequestLogRsp
/// <inheritdoc />
[CsvIndex(7)]
[CsvIgnore(false)]
[CsvName(nameof(Ln.踪标识))]
[CsvName(nameof(Ln.踪标识))]
public override Guid TraceId { get; init; }
}

View File

@ -35,7 +35,7 @@ public abstract class ApiResultHandler<T>
var result = RestfulResult(errorCode, metadata.Data
, naException is NetAdminValidateException vEx
? vEx.ValidateResults
: naException?.Message ?? errorCode.ResDesc<ErrorCodes>());
: naException?.Message ?? errorCode.ResDesc<ErrorCodes>(), context.HttpContext.GetTraceId());
SetErrorCodeToHeader(context.HttpContext, errorCode);
@ -95,9 +95,9 @@ public abstract class ApiResultHandler<T>
/// <summary>
/// 返回 RESTful 风格结果集
/// </summary>
private static T RestfulResult(ErrorCodes errorCode, object data = default, object message = default)
private static T RestfulResult(ErrorCodes errorCode, object data = null, object message = null, Guid? traceId = null)
{
return new T { Code = errorCode, Data = data, Msg = message };
return new T { Code = errorCode, Data = data, Msg = message, TraceId = traceId };
}
/// <summary>

View File

@ -7,10 +7,10 @@ namespace NetAdmin.Infrastructure.Enums;
public enum LogLevels
{
/// <summary>
///
///
/// </summary>
[Display(Name = "[gray]TCE[/]", ShortName = "TCE")]
[ResourceDescription<Ln>(nameof(Ln.踪))]
[ResourceDescription<Ln>(nameof(Ln.踪))]
Trace = 0
,

View File

@ -24,7 +24,7 @@ public static class HttpContextExtensions
}
/// <summary>
/// 获取踪标识
/// 获取踪标识
/// </summary>
public static Guid GetTraceId(this HttpContext me)
{