public static void DeleteRule(TraceRule rule, TraceFailedRequestsSection section) { if (rule == null) { return; } var collection = section.TraceRules; // To utilize the remove functionality we must pull the element directly from the collection rule = collection.FirstOrDefault(r => r.Path.Equals(rule.Path)); if (rule != null) { try { collection.Remove(rule); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } } }
public static object AddRule(TraceRule rule, TraceFailedRequestsSection section) { if (rule == null) { throw new ArgumentNullException("rule"); } if (rule.Path == null) { throw new ArgumentNullException("rule.Path"); } if (section.TraceRules.Any(r => r.Path.Equals(rule.Path, StringComparison.OrdinalIgnoreCase))) { return(new AlreadyExistsException("path")); } try { section.TraceRules.Add(rule); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } return(rule); }