Esempio n. 1
0
 public void EnableApplicationDiagnostic(
     string name,
     WebsiteDiagnosticOutput output,
     Dictionary <DiagnosticProperties, object> properties)
 {
     SetApplicationDiagnosticsSettings(name, output, true, properties);
 }
Esempio n. 2
0
        private void SetApplicationDiagnosticsSettings(
            string name,
            WebsiteDiagnosticOutput output,
            bool setFlag,
            Dictionary <DiagnosticProperties, object> properties = null)
        {
            Site website = GetWebsite(name);

            using (HttpClient client = CreateHttpClient(website.Name))
            {
                DiagnosticsSettings diagnosticsSettings = GetApplicationDiagnosticsSettings(website.Name);
                switch (output)
                {
                case WebsiteDiagnosticOutput.FileSystem:
                    diagnosticsSettings.AzureDriveTraceEnabled = setFlag;
                    diagnosticsSettings.AzureDriveTraceLevel   = setFlag ?
                                                                 (LogEntryType)properties[DiagnosticProperties.LogLevel] :
                                                                 diagnosticsSettings.AzureDriveTraceLevel;
                    break;

                case WebsiteDiagnosticOutput.StorageTable:
                    diagnosticsSettings.AzureTableTraceEnabled = setFlag;
                    if (setFlag)
                    {
                        const string storageTableName   = "CLOUD_STORAGE_ACCOUNT";
                        string       storageAccountName = (string)properties[DiagnosticProperties.StorageAccountName];

                        StorageService storageService = ServiceManagementChannel.GetStorageKeys(
                            SubscriptionId,
                            storageAccountName);
                        StorageCredentials credentials = new StorageCredentials(
                            storageAccountName,
                            storageService.StorageServiceKeys.Primary);
                        CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(credentials, false);
                        string connectionString = cloudStorageAccount.ToString(true);
                        AddAppSetting(website.Name, storageTableName, connectionString);
                        diagnosticsSettings.AzureTableTraceLevel = setFlag ?
                                                                   (LogEntryType)properties[DiagnosticProperties.LogLevel] :
                                                                   diagnosticsSettings.AzureTableTraceLevel;
                    }
                    break;

                default:
                    throw new ArgumentException();
                }

                JObject json = new JObject();
                json[UriElements.AzureDriveTraceEnabled] = diagnosticsSettings.AzureDriveTraceEnabled;
                json[UriElements.AzureDriveTraceLevel]   = JToken.FromObject(diagnosticsSettings.AzureDriveTraceLevel);
                json[UriElements.AzureTableTraceEnabled] = diagnosticsSettings.AzureTableTraceEnabled;
                json[UriElements.AzureTableTraceLevel]   = JToken.FromObject(diagnosticsSettings.AzureTableTraceLevel);
                client.PostAsJsonAsync(UriElements.DiagnosticsSettings, json, Logger);
            }
        }
Esempio n. 3
0
        private void SetApplicationDiagnosticsSettings(
            string name,
            WebsiteDiagnosticOutput output,
            bool setFlag,
            Dictionary <DiagnosticProperties, object> properties = null)
        {
            Site website = GetWebsite(name);

            using (HttpClient client = CreateDeploymentHttpClient(website.Name))
            {
                DiagnosticsSettings diagnosticsSettings = GetApplicationDiagnosticsSettings(website.Name);
                switch (output)
                {
                case WebsiteDiagnosticOutput.FileSystem:
                    diagnosticsSettings.AzureDriveTraceEnabled = setFlag;
                    diagnosticsSettings.AzureDriveTraceLevel   = setFlag ?
                                                                 (LogEntryType)properties[DiagnosticProperties.LogLevel] :
                                                                 diagnosticsSettings.AzureDriveTraceLevel;
                    break;

                case WebsiteDiagnosticOutput.StorageTable:
                    diagnosticsSettings.AzureTableTraceEnabled = setFlag;
                    if (setFlag)
                    {
                        const string storageTableName   = "CLOUD_STORAGE_ACCOUNT";
                        string       storageAccountName = (string)properties[DiagnosticProperties.StorageAccountName];
                        string       connectionString   = cloudServiceClient.GetStorageServiceConnectionString(
                            storageAccountName);
                        SetConnectionString(website.Name, storageTableName, connectionString, DatabaseType.Custom);

                        diagnosticsSettings.AzureTableTraceLevel = setFlag ?
                                                                   (LogEntryType)properties[DiagnosticProperties.LogLevel] :
                                                                   diagnosticsSettings.AzureTableTraceLevel;
                    }
                    break;

                default:
                    throw new ArgumentException();
                }

                JObject json = new JObject(
                    new JProperty(UriElements.AzureDriveTraceEnabled, diagnosticsSettings.AzureDriveTraceEnabled),
                    new JProperty(UriElements.AzureDriveTraceLevel, diagnosticsSettings.AzureDriveTraceLevel.ToString()),
                    new JProperty(UriElements.AzureTableTraceEnabled, diagnosticsSettings.AzureTableTraceEnabled),
                    new JProperty(UriElements.AzureTableTraceLevel, diagnosticsSettings.AzureTableTraceLevel.ToString()));
                client.PostJson(UriElements.DiagnosticsSettings, json, Logger);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Enables application diagnostic on website slot.
 /// </summary>
 /// <param name="name">The website name</param>
 /// <param name="output">The application log output, FileSystem or StorageTable</param>
 /// <param name="properties">The diagnostic setting properties</param>
 public void EnableApplicationDiagnostic(
     string name,
     WebsiteDiagnosticOutput output,
     Dictionary<DiagnosticProperties, object> properties)
 {
     SetApplicationDiagnosticsSettings(name, output, true, properties);
 }
Esempio n. 5
0
 /// <summary>
 /// Disables application diagnostic.
 /// </summary>
 /// <param name="name">The website name</param>
 /// <param name="output">The application log output, FileSystem or StorageTable</param>
 public void DisableApplicationDiagnostic(string name, WebsiteDiagnosticOutput output)
 {
     SetApplicationDiagnosticsSettings(name, output, false);
 }
Esempio n. 6
0
        private void SetApplicationDiagnosticsSettings(
            string name,
            WebsiteDiagnosticOutput output,
            bool setFlag,
            Dictionary<DiagnosticProperties, object> properties = null)
        {
            Utilities.Site website = GetWebsite(name);

            using (HttpClient client = CreateDeploymentHttpClient(website.Name))
            {
                DiagnosticsSettings diagnosticsSettings = GetApplicationDiagnosticsSettings(website.Name);
                switch (output)
                {
                    case WebsiteDiagnosticOutput.FileSystem:
                        diagnosticsSettings.AzureDriveTraceEnabled = setFlag;
                        diagnosticsSettings.AzureDriveTraceLevel = setFlag ?
                        (Services.DeploymentEntities.LogEntryType)properties[DiagnosticProperties.LogLevel] :
                        diagnosticsSettings.AzureDriveTraceLevel;
                        break;

                    case WebsiteDiagnosticOutput.StorageTable:
                        diagnosticsSettings.AzureTableTraceEnabled = setFlag;
                        if (setFlag)
                        {
                            string storageAccountName = (string)properties[DiagnosticProperties.StorageAccountName];
                            string storageTableName = (string)properties[DiagnosticProperties.StorageTableName];
                            string connectionString = cloudServiceClient.GetStorageServiceConnectionString(storageAccountName);

                            string tableStorageSasUrl =
                                StorageUtilities.GenerateTableStorageSasUrl(
                                    connectionString,
                                    storageTableName,
                                    DateTime.Now.AddYears(1000),
                                    SharedAccessTablePermissions.Add | SharedAccessTablePermissions.Query | SharedAccessTablePermissions.Delete | SharedAccessTablePermissions.Update);

                            SetAppSetting(name, "DIAGNOSTICS_AZURETABLESASURL", tableStorageSasUrl);

                            diagnosticsSettings.AzureTableTraceLevel = setFlag ?
                                (Services.DeploymentEntities.LogEntryType)properties[DiagnosticProperties.LogLevel] :
                                diagnosticsSettings.AzureTableTraceLevel;
                        }
                        break;

                    case WebsiteDiagnosticOutput.StorageBlob:
                        diagnosticsSettings.AzureBlobTraceEnabled = setFlag;
                        if (setFlag)
                        {
                            string storageAccountName = (string)properties[DiagnosticProperties.StorageAccountName];
                            string storageBlobContainerName = (string)properties[DiagnosticProperties.StorageBlobContainerName];
                            string connectionString = cloudServiceClient.GetStorageServiceConnectionString(storageAccountName);

                            string blobStorageSasUrl =
                                StorageUtilities.GenerateBlobStorageSasUrl(
                                    connectionString,
                                    storageBlobContainerName,
                                    DateTime.Now.AddYears(1000),
                                    SharedAccessBlobPermissions.Delete | SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write);

                            SetAppSetting(name, "DIAGNOSTICS_AZUREBLOBCONTAINERSASURL", blobStorageSasUrl);

                            diagnosticsSettings.AzureBlobTraceLevel = setFlag ?
                                (Services.DeploymentEntities.LogEntryType)properties[DiagnosticProperties.LogLevel] :
                                diagnosticsSettings.AzureBlobTraceLevel;
                        }
                        break;

                    default:
                        throw new ArgumentException();
                }

                // Check if there is null fields for diagnostics settings. If there is, default to false. (Same as defaulted on portal)
                diagnosticsSettings.AzureDriveTraceEnabled = diagnosticsSettings.AzureDriveTraceEnabled ?? false;
                diagnosticsSettings.AzureTableTraceEnabled = diagnosticsSettings.AzureTableTraceEnabled ?? false;
                diagnosticsSettings.AzureBlobTraceEnabled = diagnosticsSettings.AzureBlobTraceEnabled ?? false;

                JObject json = new JObject(
                    new JProperty(UriElements.AzureDriveTraceEnabled, diagnosticsSettings.AzureDriveTraceEnabled),
                    new JProperty(UriElements.AzureDriveTraceLevel, diagnosticsSettings.AzureDriveTraceLevel.ToString()),
                    new JProperty(UriElements.AzureTableTraceEnabled, diagnosticsSettings.AzureTableTraceEnabled),
                    new JProperty(UriElements.AzureTableTraceLevel, diagnosticsSettings.AzureTableTraceLevel.ToString()),
                    new JProperty(UriElements.AzureBlobTraceEnabled, diagnosticsSettings.AzureBlobTraceEnabled),
                    new JProperty(UriElements.AzureBlobTraceLevel, diagnosticsSettings.AzureBlobTraceLevel.ToString()));
                client.PostJson(UriElements.DiagnosticsSettings, json, Logger);
            }
        }
Esempio n. 7
0
        private void SetApplicationDiagnosticsSettings(
            string name,
            WebsiteDiagnosticOutput output,
            bool setFlag,
            Dictionary<DiagnosticProperties, object> properties = null)
        {
            Site website = GetWebsite(name);

            using (HttpClient client = CreateDeploymentHttpClient(website.Name))
            {
                DiagnosticsSettings diagnosticsSettings = GetApplicationDiagnosticsSettings(website.Name);
                switch (output)
                {
                    case WebsiteDiagnosticOutput.FileSystem:
                        diagnosticsSettings.AzureDriveTraceEnabled = setFlag;
                        diagnosticsSettings.AzureDriveTraceLevel = setFlag ?
                        (LogEntryType)properties[DiagnosticProperties.LogLevel] :
                        diagnosticsSettings.AzureDriveTraceLevel;
                        break;

                    case WebsiteDiagnosticOutput.StorageTable:
                        diagnosticsSettings.AzureTableTraceEnabled = setFlag;
                        if (setFlag)
                        {
                            const string storageTableName = "CLOUD_STORAGE_ACCOUNT";
                            string storageAccountName = (string)properties[DiagnosticProperties.StorageAccountName];
                            string connectionString = cloudServiceClient.GetStorageServiceConnectionString(
                                storageAccountName);
                            SetConnectionString(website.Name, storageTableName, connectionString, DatabaseType.Custom);

                            diagnosticsSettings.AzureTableTraceLevel = setFlag ?
                                (LogEntryType)properties[DiagnosticProperties.LogLevel] :
                                diagnosticsSettings.AzureTableTraceLevel;
                        }
                        break;

                    default:
                        throw new ArgumentException();
                }

                JObject json = new JObject(
                    new JProperty(UriElements.AzureDriveTraceEnabled, diagnosticsSettings.AzureDriveTraceEnabled),
                    new JProperty(UriElements.AzureDriveTraceLevel, diagnosticsSettings.AzureDriveTraceLevel.ToString()),
                    new JProperty(UriElements.AzureTableTraceEnabled, diagnosticsSettings.AzureTableTraceEnabled),
                    new JProperty(UriElements.AzureTableTraceLevel, diagnosticsSettings.AzureTableTraceLevel.ToString()));
                client.PostJson(UriElements.DiagnosticsSettings, json, Logger);
            }
        }
Esempio n. 8
0
 public void DisableApplicationDiagnostic(string name, WebsiteDiagnosticOutput output)
 {
     SetApplicationDiagnosticsSettings(name, output, false);
 }
        private void SetApplicationDiagnosticsSettings(
            string name,
            WebsiteDiagnosticOutput output,
            bool setFlag,
            Dictionary<DiagnosticProperties, object> properties = null)
        {
            Site website = GetWebsite(name);

            using (HttpClient client = CreateDeploymentHttpClient(website.Name))
            {
                DiagnosticsSettings diagnosticsSettings = GetApplicationDiagnosticsSettings(website.Name);
                switch (output)
                {
                    case WebsiteDiagnosticOutput.FileSystem:
                        diagnosticsSettings.AzureDriveTraceEnabled = setFlag;
                        diagnosticsSettings.AzureDriveTraceLevel = setFlag ?
                        (LogEntryType)properties[DiagnosticProperties.LogLevel] :
                        diagnosticsSettings.AzureDriveTraceLevel;
                        break;

                    case WebsiteDiagnosticOutput.StorageTable:
                        diagnosticsSettings.AzureTableTraceEnabled = setFlag;
                        if (setFlag)
                        {
                            const string storageTableName = "CLOUD_STORAGE_ACCOUNT";
                            string storageAccountName = (string)properties[DiagnosticProperties.StorageAccountName];

                            StorageService storageService = ServiceManagementChannel.GetStorageKeys(
                                subscriptionId,
                                storageAccountName);
                            StorageCredentials credentials = new StorageCredentials(
                                storageAccountName,
                                storageService.StorageServiceKeys.Primary);
                            CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(credentials, false);
                            string connectionString = cloudStorageAccount.ToString(true);
                            AddAppSetting(website.Name, storageTableName, connectionString);
                            diagnosticsSettings.AzureTableTraceLevel = setFlag ?
                                (LogEntryType)properties[DiagnosticProperties.LogLevel] :
                                diagnosticsSettings.AzureTableTraceLevel;
                        }
                        break;

                    default:
                        throw new ArgumentException();
                }

                JObject json = new JObject();
                json[UriElements.AzureDriveTraceEnabled] = diagnosticsSettings.AzureDriveTraceEnabled;
                json[UriElements.AzureDriveTraceLevel] = JToken.FromObject(diagnosticsSettings.AzureDriveTraceLevel);
                json[UriElements.AzureTableTraceEnabled] = diagnosticsSettings.AzureTableTraceEnabled;
                json[UriElements.AzureTableTraceLevel] = JToken.FromObject(diagnosticsSettings.AzureTableTraceLevel);
                client.PostAsJsonAsync(UriElements.DiagnosticsSettings, json, Logger);
            }
        }