How to support multiple Azure subscriptions for a single application with application insights

孤者浪人 提交于 2019-12-12 01:47:55

问题


I'm running VS 2013 Update 3 and have a Cloud Service with App Insights installed. That is all good and well. However, I have three different subscriptions (dev, staging, and production) and want my dev cloud service instance to report app insights data to my dev subscription while my staging cloud service instance reports app insights data to my staging subscription. How can I configure this single cloud app to report data to different subscriptions and/or app insights app names?


回答1:


I ended up going with the following within:

public class ConfigSettings
{
    internal class AppInsights
    {
        internal static bool IsEnabled
        {
            get
            {
                return CloudConfigurationManager.GetSetting("AppInsights.IsEnabled").Cast<bool>();
            }
        }

        internal static string InstrumentationKey
        {
            get
            {
                return CloudConfigurationManager.GetSetting("AppInsights.InstrumentationKey");
            }
        }
    }
}

public class AppInsightsHelper
{
    public static void Initialize()
    {
        if(ConfigSettings.AppInsights.IsEnabled)
            TelemetryConfiguration.Active.InstrumentationKey = ConfigSettings.AppInsights.InstrumentationKey;
    }
}

// In global.asax.cs
AppInsightsHelper.Initialize();


来源:https://stackoverflow.com/questions/26206673/how-to-support-multiple-azure-subscriptions-for-a-single-application-with-applic

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