'NLog: Remove logging rule by name if it was added without name by LoggingConfiguration.AddRule()?

I am new to NLog, but I think I have got a good understand of how it works in the last hours.

After digging deeper into NLog API, several questions about Logging Rules come up. One of them is:
How can I remove a rule by name (using LoggingConfiguration.RemoveRuleByName()) that I have added programmatically by LoggingConfiguration.AddRule() before?

  • LoggingConfiguration.AddRule() does not provide an argument to set the LoggingRule.RuleName.
  • LoggingConfiguration.AddRule() does not take a LoggingRule object.
  • I don't want to check every rule in the LoggingConfiguration.LoggingRules collection, because this would mean checking them by content, because I cannot set a name.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source