public void Remove_NullAreaDoesntThrowException()
        {
            //Arrange
            MockConfigManager         config = new MockConfigManager();
            DiagnosticsAreaCollection areas  = new DiagnosticsAreaCollection(config);

            //Act
            areas.Remove(null);

            // Assert - no action required, it should be a no-op
        }
        /// <summary>
        /// Unregisters the logger source.
        /// </summary>
        /// <param name="loggingArea">The logging area.</param>
        public static void UnregisterLoggerSource(string loggingArea)
        {
            IConfigManager            _configMgr       = SharePointServiceLocator.GetCurrent().GetInstance <IConfigManager>();
            DiagnosticsAreaCollection _configuredAreas = new DiagnosticsAreaCollection(_configMgr);
            DiagnosticsArea           areaToRemove     = _configuredAreas[loggingArea];

            if (areaToRemove != null)
            {
                _configuredAreas.Remove(areaToRemove);
            }
            _configuredAreas.SaveConfiguration();
        }
        public void Remove_AreaRemoveDefault()
        {
            //Arrange
            MockConfigManager         config = new MockConfigManager();
            DiagnosticsAreaCollection areas  = new DiagnosticsAreaCollection(config);

            DiagnosticsArea     area     = new DiagnosticsArea(MockConfigManager.Area2Name);
            DiagnosticsCategory category = new DiagnosticsCategory(MockConfigManager.Area2Category1Name);

            area.DiagnosticsCategories.Add(category);
            int             areasCount   = areas.Count;
            DiagnosticsArea originalArea = areas[MockConfigManager.Area2Name];

            //Act
            bool isRemoved = areas.Remove(originalArea);

            //Assert
            Assert.IsTrue(isRemoved);
            Assert.IsNull(areas[MockConfigManager.Area2Name]);
        }
Beispiel #4
0
        public bool RemoveDiagnosticArea(DiagnosticsArea area)
        {
            bool            retVal       = false;
            DiagnosticsArea areaToRemove = configuredAreas[area.Name];

            if (areaToRemove != null)
            {
                foreach (DiagnosticsCategory c in area.DiagnosticsCategories)
                {
                    var existingCat = areaToRemove.DiagnosticsCategories[c.Name];
                    if (existingCat != null)
                    {
                        areaToRemove.DiagnosticsCategories.Remove(existingCat);
                    }
                }
                if (areaToRemove.DiagnosticsCategories.Count == 0)
                {
                    configuredAreas.Remove(areaToRemove);
                }
            }
            return(retVal);
        }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            var configManager = SharePointServiceLocator.GetCurrent().GetInstance<IConfigManager>();
            var configuredAreas = new DiagnosticsAreaCollection(configManager);

            foreach (var area in Areas)
            {
                var areaToRemove = configuredAreas[area.Name];

                if (areaToRemove != null)
                {
                    foreach (var c in area.DiagnosticsCategories)
                    {
                        var existingCat = areaToRemove.DiagnosticsCategories[c.Name];
                        if (existingCat != null)
                        {
                            areaToRemove.DiagnosticsCategories.Remove(existingCat);
                        }
                    }

                    if (areaToRemove.DiagnosticsCategories.Count == 0)
                    {
                        configuredAreas.Remove(areaToRemove);
                    }
                }
            }

            configuredAreas.SaveConfiguration();
        }