Suppressing Console Logging by Azure KeyVault

雨燕双飞 提交于 2020-02-24 11:42:26

问题


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.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

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?


回答1:


According to your description, I checked the source code of Microsoft.Azure.KeyVault, but did not find any relevant logging.

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

Based on the log information, I tried to leverage ILSpy to decompile the package Microsoft.IdentityModel.Clients.ActiveDirectory and found the following code:

You could disable the trace logging under ADAL library via the following code:

LoggerCallbackHandler.UseDefaultLogging = false;

TEST:




回答2:


For version of 2.x of Microsoft.IdentityModel.Clients.ActiveDirectory, you'll need to call this:

using Microsoft.IdentityModel.Clients.ActiveDirectory;

AdalTrace.LegacyTraceSwitch.Level = TraceLevel.Error;

For version 3.x+ use Bruce_Chen's answer:

LoggerCallbackHandler.UseDefaultLogging = false;



来源:https://stackoverflow.com/questions/47982194/suppressing-console-logging-by-azure-keyvault

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!