问题描述
我正在Net Core 2控制台应用程序中使用C#访问Azure密钥库.每当运行该应用程序时,当我从库中检索秘密时,控制台窗口就会显示如下消息:
I'm accessing an Azure key vault, using C#, in a Net Core 2 console app. Whenever the app runs, the console window gets hit with messages like this when I retrieve a secret from the vault:
2017-12-26T18:03:49.8981211Z:29c98a86-9e1d-4a5d-86d6-daf8f2cfdc56- AcquireTokenHandlerBase.cs:从缓存加载.
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:在缓存中查找令牌...
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:在缓存中找不到匹配的令牌
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:将令牌存储在缓存中...
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:项目已存储在缓存中
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:===令牌获取完成 成功地.访问令牌已重新调整:
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
我不记得要在代码中做任何事情来设置密钥库访问的任何类型的日志记录.但是,我已经在整个应用程序中配置了Serilog的ILogger,所以也许以某种方式被采用了.
I don't recall doing anything in my code to set up any kind of logging for the key vault access. However, I have configured Serilog's ILogger throughout the app, so maybe that's being picked up, somehow.
如何禁止显示这些消息?
How do I suppress these messages from being displayed?
推荐答案
根据您的描述,我检查了 Microsoft.Azure.KeyVault ,但未找到任何相关的日志记录.
According to your description, I checked the source code of Microsoft.Azure.KeyVault, but did not find any relevant logging.
根据日志信息,我尝试利用 ILSpy 来反编译软件包 Microsoft.IdentityModel.Clients.ActiveDirectory 并找到以下代码:
Based on the log information, I tried to leverage ILSpy to decompile the package Microsoft.IdentityModel.Clients.ActiveDirectory and found the following code:
您可以通过以下代码在ADAL库下禁用跟踪日志记录:
You could disable the trace logging under ADAL library via the following code:
LoggerCallbackHandler.UseDefaultLogging = false;
测试:
这篇关于通过Azure KeyVault禁止控制台日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!