Type:
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.
Type:
NLog version: 4.4.12
Platform: .Net 4.5
The
Idproperty of classLoggingRulecan be used to locate exact rule in code, otherwise, we have to code a lot to find the rule we want:So, if there is an
Idproperty, we can do this:Not only for
LoggingRuleclass, but all that can be accessed by code should have anIdproperty or something else which can be used to locate them in code like Linq calls.