Type:
NLog version: 4.4.12
Platform: .Net 4.5
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:So, if there is an `Id` property, we can do this:
```C#
var rule = config.LoggingRules
.FirstOrDefault(r => "ruleYouWant" == r.Id);
<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.
I like the idea!
Currently you could use the index as a poor man's solution
Haha, yes a poor man's solution indeed o(≧▽≦)o
In fact sometimes the index can be of help, but in a more complex application, the index way have a problem is that, we can not ensure that rules added by code always take the same indexes, so currently checking all properties is the most stable way.
I'm looking forward to this feature getting online ;)
I like the idea, and it's easy to implement, but there is one issue:
<logger name="myname" writeTo="trace"/>
this means: filter the logs on the name "myname"
<logger id="myname" writeTo="trace"/>
And this won't filter on an id or something. It could be confusing. Yes the name of name attribute if bad, but we can't change it. What do you guys think?
I think id should be ok. If it's explained in the docu it should be enough.
Whats about "alias", "accessId" , "apiAccessId" or something like that?
Im thinking of rule-name or rule-id
2 times a config value with "name" in it? I prefer "rule-id"
OK, and should be enforce an unique id?
Should be there a method to get the rules as dictionary? (id -> rule) - how do you think we should handle duplicate ids?
Method would be nice but not a must. With simple linq statement I will find the required role.
For duplicates I suggest only to write into internal log and throw exception of enabled.
@snakefoot any opinion on this one?
@snakefoot any opinion on this one?
Seldom working with runtime configuration of NLog, so don't have much input. The easy solution would be to just add a non-unique Name-property to the LoggingRule (Not sure why this is rejected).
The easy solution would be to just add a non-unique Name-property to the LoggingRule (Not sure why this is rejected).
What's rejected?
What's rejected?
Totally forgot that the Xml-config had the name-alias. Yes then it has to be something else than "name" :)
Little confusing that one can use name-property in xml, but it is called LoggerNamePattern in code.
Think "Id" is good then, but then it has to been unique, and all loggingrules without id should get an auto-guid. Could be that changing to Dictionary-container will be a somewhat more complicated.
Maybe instead of "Id" then it could be "Tag", thus not introducing an unique-constraint.
Little confusing that one can use name-property in xml, but it is called LoggerNamePattern in code.
true, confusing. Maybe change it in NLog 5
Maybe instead of "Id" then it could be "Tag", thus not introducing an unique-constraint.
I only like tagging when it supports multiple tags ;)
I'm also fine by using a ID (attribute will be rule-id) and skipping the duplicate IDS when building a dictionary. Like HTML
I only like tagging when it supports multiple tags ;)
I only expect that when the property is called Tags and is a collection :)
I'm also fine by using a ID (attribute will be rule-id) and skipping the duplicate IDS when building a dictionary. Like HTML
Think that will give a very bad user-experience if only enforcing the constraint, when requesting the collection as dictionary. Should it throw exceptions when building the dictionary? (Like Linq.ToDictionary)
It could also be called label, but then you would probably argue that it should have more labels. Another alternative is alias.
I only expect that when the property is called Tags and is a collection :)
true, but tagging is IMO strange when only one tag could be applied.
Think that will give a very bad user-experience if only enforcing the constraint, when requesting the collection as dictionary. Should it throw exceptions when building the dictionary? (Like Linq.ToDictionary)
good one, exception is indeed better.
good one, exception is indeed better.
I would prefer that if adding "Id"-property, then it should validate it being unique at insert, instead of at a random point later.
yes and the exception is dependent of throwConfigExceptions
I think non-unique Name-property with the name of ruleName should be OK.
The reason for non-unique is that maybe we want to locate a group of rules, if the accessor is unique, the batch operations are still complicated.
The word 'Id' can give an impression that this is an unique identifier which was similar to 'id' property of html tags. So, I prefer ruleName if the property is non-unique, otherwise, ruleId for unique.
The other solution is, a Group property for locate multiple(grouped) rules, meanwhile, the ruleId for accurately locate an unique rule. Of course, there is alternative ways that you can use string.StartsWith in .Where() Linq calls for unique id property to locate multiple rules with same prefix .
Personally, I prefer the non-unique ruleName, and this is the most simple and clean solution: please don't make the api complex.
Is it not possible to create child rules for groupping propose?
Is this feature available during the next weeks?
I think it will be 4.6, or if a PR is sent, ealier
Resolved with #2891
FYI, NLog 4.6 RC is online which includes this feature
Most helpful comment
Resolved with #2891