LoggingConfigurationParser - Extracted from XmlLoggingConfiguration + rule name for <rule> + logger attribute for filtering#2891
Conversation
b17f81d to
3ef294f
Compare
304NotModified
left a comment
There was a problem hiding this comment.
(Handle reordering when dictionary etc.)
I think the rule should be, don't use dictionaries when the ordering is important in JSON. A list with items with an "id" is more inline with the JSON standard then.
| return false; | ||
| } | ||
|
|
||
| private object ParseArrayItemFromElement(Type elementType, ILoggingConfigurationSection element) |
There was a problem hiding this comment.
I think the name is a confusing here (and in more paths). Is a section or an element?
There was a problem hiding this comment.
proposal: ILoggingConfigurationElement or ILoggingConfigurationItem
| /// <summary> | ||
| /// Rule identifier to allow rule lookup | ||
| /// </summary> | ||
| public string RuleName { get; } |
There was a problem hiding this comment.
Yes. And now also added LoggingConfiguration.FindRuleByName and RemoveRuleByName. Together with a little unit-test to verify they work.
There was a problem hiding this comment.
I've a question about this. Is this a new attribute in the XML? or can't be set it from the XML?
There was a problem hiding this comment.
Like I said. You should not use <logger> but instead <rule> . Just like <targets> and <target>.
<rules>
<rule name="hello" logger="*" minlevel="Info" writeTo="logconsole" />
<rule name="world" logger="*" minlevel="Debug" writeTo="logfile" />
</rules>
There was a problem hiding this comment.
Ofcourse you can continue to use <logger> but then you cannot specify the rule-name
There was a problem hiding this comment.
ow I didn't got that!
Do you really think that's a good idea? I have to agree "name" was a bad name (no pun intended), but a lot of docs uses of course name=*
There was a problem hiding this comment.
it sounds like writing a long and good post about this, but you've maybe noticed I don't like writings blogs/newposts ;) (#2626)
There was a problem hiding this comment.
Seems that rule element is not added to NLog.Schema yet?
|
I think this is the right direction! :) (PS doubting of ConfigurationParseBase for the abstract class) |
3ef294f to
3e62691
Compare
Can only agree. But there are some funny business. Ex variables-section should be parsed first. Same goes for But anyway all that extra Json-specific logic is now hidden away in my homemade ExtensionLoggingConfiguration (Depends on But if variables in the variables-section references other variables. Then it is very important that the variables are declared using array instead of using dictionary. Because there is no logic in my homemade config-parser to reorder variables to ensure variable-references have been pre-added. |
5d48006 to
4f9c22b
Compare
Codecov Report
@@ Coverage Diff @@
## dev #2891 +/- ##
======================================
- Coverage 81% 80% -<1%
======================================
Files 327 328 +1
Lines 24687 24911 +224
Branches 3171 3226 +55
======================================
+ Hits 19899 20006 +107
- Misses 3924 3995 +71
- Partials 864 910 +46 |
4f9c22b to
fe40508
Compare
<logger>
<logger><logger> + logger attribute for filtering
<logger> + logger attribute for filtering<rule> + logger attribute for filtering
|
it sounds like writing a long and good post about this, but you've maybe noticted I don't like writings blogs/newposts
No need to write anything. You can already use <appender> or <target> and now you can use <logger> or <rule>
|
|
ok merged, thanks! |
|
This works now in NLog 4.6.4: |
|
Is it really "rulename"? It looks like it parses "name": |
|
Changes currently lives in a branch called release/4.6.4
At some point it will be merged to dev and master branch
|
|
See NLog/src/NLog/Config/LoggingConfigurationParser.cs Lines 593 to 594 in b83d37f |
Retry of #2624. Where most JSON hacks have been removed (Only Array remains). Means more effort has to be put into the JsonLoggingConfiguration (Handle reordering when dictionary etc.)
There is a little "hack" around logging-rules, where this behaves the old way, where name specifies logger-wildcard:
<logger name="hello" final="true" />And this creates a logging rule that can be identified with the name and matches the specified logger-wildcard:
<rule name="myname" logger="hello" final="true" />This change is