gpt4 book ai didi

c# - 通过 Azure KeyVault 禁止控制台日志记录

转载 作者:行者123 更新时间:2023-11-30 20:16:44 24 4
gpt4 key购买 nike

我正在 Net Core 2 控制台应用程序中使用 C# 访问 Azure key 保管库。每当应用程序运行时,当我从保管库检索 secret 时,控制台窗口都会收到如下消息:

2017-12-26T18:03:49.8610049Z: 29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56 - AcquireTokenHandlerBase.cs: ADAL PCL.CoreCLR with assembly version '3.17.3.35304', file version '3.17.41219.2324' and informational version 'b6afaeae7cff965e66649e0ee7e8c29071d5a7e6' is running... 2017-12-26T18:03:49.8621855Z: 29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56 - AcquireTokenHandlerBase.cs: === Token Acquisition started: Authority: https://login.windows.net/[...]/ Resource: https://vault.azure.net ClientId: [...] CacheType: null Authentication Target: Client

2017-12-26T18:03:49.8981211Z: 29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56 - AcquireTokenHandlerBase.cs: Loading from cache.

2017-12-26T18:03:49.9010018Z: 29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56 - TokenCache.cs: Looking up cache for a token...

2017-12-26T18:03:49.9060990Z: 29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56 - TokenCache.cs: No matching token was found in the cache

2017-12-26T18:03:50.2185881Z: 29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56 - TokenCache.cs: Storing token in the cache...

2017-12-26T18:03:50.2211369Z: 29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56 - TokenCache.cs: An item was stored in the cache

2017-12-26T18:03:50.2351165Z: 29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56 - AcquireTokenHandlerBase.cs: === Token Acquisition finished successfully. An access token was retuned:

    Access Token Hash: [...]
Expiration Time: 12/26/2017 7:03:49 PM +00:00
User Hash: null

我不记得在代码中执行过任何操作来为 key 保管库访问设置任何类型的日志记录。不过,我已经在整个应用程序中配置了 Serilog 的 ILogger,所以也许会以某种方式拾取它。

如何禁止显示这些消息?

最佳答案

根据你的描述,我查了Microsoft.Azure.KeyVault的源码,但没有找到任何相关的日志记录。

2017-12-26T18:03:49.8610049Z: 29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56 - AcquireTokenHandlerBase.cs: ADAL PCL.CoreCLR with assembly version '3.17.3.35304', file version '3.17.41219.2324' and informational version

根据日志信息,我尝试利用ILSpy反编译包Microsoft.IdentityModel.Clients.ActiveDirectory并找到以下代码:

enter image description here

enter image description here

您可以通过以下代码禁用 ADAL 库下的跟踪日志记录:

LoggerCallbackHandler.UseDefaultLogging = false;

测试:

enter image description here

关于c# - 通过 Azure KeyVault 禁止控制台日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47982194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com