private void EnableWhenDiagnosticsEnablingAuditCategoryDoNotExist(SqlAuditAdapter adapter, DiagnosticSettingsResource currentSettings = null)
        {
            if (adapter.CreateDiagnosticSettings(
                    GetEventHubNameOnCreateOrUpdate(currentSettings),
                    GetEventHubAuthorizationRuleIdOnCreateOrUpdate(currentSettings),
                    GetWorkspaceIdOnCreateOrUpdate(currentSettings),
                    this) == false)
            {
                throw DefinitionsCommon.CreateDiagnosticSettingsException;
            }

            try
            {
                IsGlobalAuditEnabled        = true;
                IsAzureMonitorTargetEnabled = true;
                if (SetAuditingPolicy(adapter) == false)
                {
                    throw DefinitionsCommon.SetAuditingSettingsException;
                }
            }
            catch (Exception)
            {
                try
                {
                    adapter.RemoveDiagnosticSettings(this);
                }
                catch (Exception) { }

                throw;
            }
        }
Beispiel #2
0
        private void DisableWhenOnlyAuditCategoryIsEnabled(SqlAuditAdapter adapter, DiagnosticSettingsResource settings, string oldEventHubName, string oldEventHubAuthorizationRuleId, string oldWorkspaceId)
        {
            if (ShoudDiagnosticSettingsBeRemovedOnDisabledPolicy(settings))
            {
                if (adapter.RemoveDiagnosticSettings(this) == false)
                {
                    throw new Exception("Failed to remove Diagnostic Settings");
                }

                try
                {
                    DisableWhenDiagnosticsEnablingAuditCategoryDoNotExist(adapter);
                }
                catch (Exception)
                {
                    try
                    {
                        adapter.CreateDiagnosticSettings(oldEventHubName,
                                                         oldEventHubAuthorizationRuleId, oldWorkspaceId, this);
                    }
                    catch (Exception) { }

                    throw;
                }
            }
            else
            {
                settings.EventHubName = GetEventHubNameOnDisablePolicy(settings);
                settings.EventHubAuthorizationRuleId = GetEventHubAuthorizationRuleIdOnDisablePolicy(settings);
                settings.WorkspaceId = GetWorkspaceIdOnOnDisablePolicy(settings);
                if (adapter.UpdateDiagnosticSettings(settings, this) == false)
                {
                    throw DefinitionsCommon.UpdateDiagnosticSettingsException;
                }
            }
        }