How do I make CloudConfigurationManager.GetSetting less verbose?

后端 未结 8 1424
天命终不由人
天命终不由人 2021-01-04 01:05

I\'m currently using CloudConfigurationManager.GetSetting(\"setting\") to get settings for my application, but it\'s writing logs of everything it\'s checking to the console

8条回答
  •  猫巷女王i
    2021-01-04 01:40

    CloudConfigurationManager.GetSetting now has a method overload with a parameter called outputResultsToTrace.

    If you pass false to this method, then it'll disable the Trace.WriteLine used elsewhere to "spam" the Trace log.

    So

    var mySetting = CloudConfigurationManager.GetSetting("MySetting");
    

    becomes

    var mySetting = CloudConfigurationManager.GetSetting("MySetting", false);
    

    I found this by looking directly at the source code on GitHub: https://github.com/Azure/azure-sdk-for-net/blob/52fc67253a176bea01c37c164f71c7eba8eaedba/src/Common/Configuration/CloudConfigurationManager.cs#L35

    It's probably worth mentioning that this overload is not documented: https://msdn.microsoft.com/en-us/library/azure/mt634648.aspx

    So I'm not sure if it's an official and supported part of the API, or if it's something that might change or go away in the future.

    This change was made at the end of 2015: https://github.com/Azure/azure-sdk-for-net/commit/e14398136d7d3b6d5e4675f1e8ccbdd37a8c6b01

提交回复
热议问题