diag: Optional=false 强制暴露 Consul 错误
This commit is contained in:
parent
23a2aa95fc
commit
ec06a95bc5
@ -32,13 +32,14 @@ builder.Configuration.AddConsul(
|
||||
// 默认 ConvertConsulKVPairToConfig 把 Consul key 路径(去 buildflow/ 前缀,/ 转 :)作为 IConfiguration key,
|
||||
// 如 buildflow/Jwt:SigningKey → 配置 Jwt:SigningKey,value 直接是密钥字符串。
|
||||
options.Parser = new SimpleConfigurationParser();
|
||||
options.Optional = true; // Consul 不可用不阻断启动,回退本地 appsettings
|
||||
options.Optional = false; // 诊断期:强制 Consul 必须可用,暴露真实错误
|
||||
options.ReloadOnChange = true; // KV 变更自动刷新 IConfiguration(热重载基础)
|
||||
// 诊断期:打印 Consul 加载异常(确认后改回 Ignore)
|
||||
options.OnLoadException = ex =>
|
||||
{
|
||||
Console.WriteLine($"[Consul] 加载异常: {ex.Exception?.GetType().Name}: {ex.Exception?.Message}");
|
||||
ex.Ignore = true;
|
||||
Console.WriteLine($"[Consul] 堆栈: {ex.Exception?.StackTrace?.Substring(0, System.Math.Min(500, ex.Exception?.StackTrace?.Length ?? 0))}");
|
||||
ex.Ignore = false; // 不吞,让异常抛出
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user