Skip to content

Support for RuleName property on a <Rule> (LoggingRule class) #2394

@qaqz111

Description

@qaqz111

Type:

  • Feature request

NLog version: 4.4.12

Platform: .Net 4.5

  • Why do we need it?
    The Id property of class LoggingRule can be used to locate exact rule in code, otherwise, we have to code a lot to find the rule we want:
            var rule = config.LoggingRules
                .FirstOrDefault(r =>
                    "*" == r.LoggerNamePattern &&
                    false == r.Final &&
                    (null == r.ChildRules || 0 == r.ChildRules.Count) &&
                    (null == r.Filters || 0 == r.Filters.Count) &&
                    (null != r.Levels && 5 == r.Levels.Count) &&
                    (null != r.Targets && 2 == r.Targets.Count));

So, if there is an Id property, we can do this:

            var rule = config.LoggingRules
                .FirstOrDefault(r => "ruleYouWant" == r.Id);
  • An example of the XML config, if relevant.
  <rules>
    <logger name="*" writeTo="trace"/>
    <logger id="ruleYouWant" name="*" minlevel="Debug" writeTo="con,file"/>
  </rules>

Not only for LoggingRule class, but all that can be accessed by code should have an Id property or something else which can be used to locate them in code like Linq calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions