Ejemplo n.º 1
0
        public async Task <ApplicationInsightsComponent> CreateApplicationInsightsComponentAsync(
            IResourceGroup resourceGroup,
            string applicationInsightsName,
            IDictionary <string, string> tags   = null,
            CancellationToken cancellationToken = default
            )
        {
            try {
                tags ??= new Dictionary <string, string>();

                Log.Information($"Creating Azure Application Insights Component: {applicationInsightsName} ...");

                var applicationInsightsComponentParameters = new ApplicationInsightsComponent()
                {
                    Location = resourceGroup.RegionName,
                    Tags     = tags,

                    Kind            = APPLICATION_INSIGHTS_COMPONENT_KIND,
                    ApplicationType = APPLICATION_INSIGHTS_COMPONENT_APPLICATION_TYPE
                };

                applicationInsightsComponentParameters.Validate();

                var applicationInsightsComponent = await _applicationInsightsManagementClient
                                                   .Components
                                                   .CreateOrUpdateAsync(
                    resourceGroup.Name,
                    applicationInsightsName,
                    applicationInsightsComponentParameters,
                    cancellationToken
                    );

                var applicationInsightsComponentBillingFeaturesParameters = new ApplicationInsightsComponentBillingFeatures()
                {
                    CurrentBillingFeatures = new List <string> {
                        "Basic"
                    },

                    // ResetTime is get only, so not available through object initializers
                    DataVolumeCap = new ApplicationInsightsComponentDataVolumeCap(
                        cap: 100.0,
                        resetTime: 24,
                        warningThreshold: 90
                        )
                };

                var applicationInsightsComponentBillingFeatures = await _applicationInsightsManagementClient
                                                                  .ComponentCurrentBillingFeatures
                                                                  .UpdateAsync(
                    resourceGroup.Name,
                    applicationInsightsName,
                    applicationInsightsComponentBillingFeaturesParameters,
                    cancellationToken
                    );

                Log.Information($"Created Azure Application Insights Component: {applicationInsightsName}");

                return(applicationInsightsComponent);
            }
            catch (Exception ex) {
                Log.Error(ex, $"Failed to create Azure Application Insights Component: {applicationInsightsName}");
                throw;
            }
        }