Skip to content

LoggingConfigurationParser - Extracted from XmlLoggingConfiguration + rule name for <rule> + logger attribute for filtering#2891

Merged
304NotModified merged 1 commit intoNLog:devfrom
snakefoot:LoggingConfigurationReader
Sep 23, 2018
Merged

Conversation

@snakefoot
Copy link
Copy Markdown
Contributor

@snakefoot snakefoot commented Aug 31, 2018

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 Reviewable

@snakefoot snakefoot force-pushed the LoggingConfigurationReader branch 2 times, most recently from b17f81d to 3ef294f Compare September 1, 2018 07:17
@snakefoot snakefoot changed the title LoggingConfigurationReader - Extracted from XmlLoggingConfiguration LoggingConfigurationParser - Extracted from XmlLoggingConfiguration Sep 1, 2018
@snakefoot snakefoot changed the title LoggingConfigurationParser - Extracted from XmlLoggingConfiguration WIP: LoggingConfigurationParser - Extracted from XmlLoggingConfiguration Sep 1, 2018
@304NotModified 304NotModified self-assigned this Sep 1, 2018
Copy link
Copy Markdown
Member

@304NotModified 304NotModified left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name is a confusing here (and in more paths). Is a section or an element?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposal: ILoggingConfigurationElement or ILoggingConfigurationItem

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

/// <summary>
/// Rule identifier to allow rule lookup
/// </summary>
public string RuleName { get; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes #2394 isn't?

Copy link
Copy Markdown
Contributor Author

@snakefoot snakefoot Sep 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. And now also added LoggingConfiguration.FindRuleByName and RemoveRuleByName. Together with a little unit-test to verify they work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've a question about this. Is this a new attribute in the XML? or can't be set it from the XML?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snakefoot bump

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ofcourse you can continue to use <logger> but then you cannot specify the rule-name

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=*

Copy link
Copy Markdown
Member

@304NotModified 304NotModified Sep 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it sounds like writing a long and good post about this, but you've maybe noticed I don't like writings blogs/newposts ;) (#2626)

Copy link
Copy Markdown

@qaqz111 qaqz111 Apr 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that rule element is not added to NLog.Schema yet?

@304NotModified
Copy link
Copy Markdown
Member

I think this is the right direction! :)

(PS doubting of ConfigurationParseBase for the abstract class)

@snakefoot snakefoot force-pushed the LoggingConfigurationReader branch from 3ef294f to 3e62691 Compare September 1, 2018 22:35
@snakefoot
Copy link
Copy Markdown
Contributor Author

snakefoot commented Sep 1, 2018

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.

Can only agree. But there are some funny business. Ex variables-section should be parsed first. Same goes for default-target-parameters and default-wrapper in the targets-section. (Just like the default parser already helps with loading extensions first, and logging-rules last).

But anyway all that extra Json-specific logic is now hidden away in my homemade ExtensionLoggingConfiguration (Depends on Microsoft.Extensions.Configuration.Abstractions). It looks okay to me, and with can load Json-Files nicely with help from Microsoft.Extensions.Configuration.Json.

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.

@snakefoot snakefoot force-pushed the LoggingConfigurationReader branch 3 times, most recently from 5d48006 to 4f9c22b Compare September 1, 2018 22:57
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 1, 2018

Codecov Report

Merging #2891 into dev will decrease coverage by <1%.
The diff coverage is 80%.

@@          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

@snakefoot snakefoot changed the title WIP: LoggingConfigurationParser - Extracted from XmlLoggingConfiguration LoggingConfigurationParser - Extracted from XmlLoggingConfiguration Sep 1, 2018
@snakefoot snakefoot force-pushed the LoggingConfigurationReader branch from 4f9c22b to fe40508 Compare September 1, 2018 23:07
@304NotModified 304NotModified changed the title LoggingConfigurationParser - Extracted from XmlLoggingConfiguration LoggingConfigurationParser - Extracted from XmlLoggingConfiguration + rule name for <logger> Sep 18, 2018
@304NotModified 304NotModified changed the title LoggingConfigurationParser - Extracted from XmlLoggingConfiguration + rule name for <logger> LoggingConfigurationParser - Extracted from XmlLoggingConfiguration + rule name for <logger> + logger attribute for filtering Sep 23, 2018
@304NotModified 304NotModified changed the title LoggingConfigurationParser - Extracted from XmlLoggingConfiguration + rule name for <logger> + logger attribute for filtering LoggingConfigurationParser - Extracted from XmlLoggingConfiguration + rule name for <rule> + logger attribute for filtering Sep 23, 2018
@snakefoot
Copy link
Copy Markdown
Contributor Author

snakefoot commented Sep 23, 2018 via email

@304NotModified 304NotModified merged commit 650ea5d into NLog:dev Sep 23, 2018
@304NotModified
Copy link
Copy Markdown
Member

ok merged, thanks!

@304NotModified
Copy link
Copy Markdown
Member

@304NotModified
Copy link
Copy Markdown
Member

304NotModified commented May 23, 2019

This works now in NLog 4.6.4:

<logger name="hello" final="true" rulename="name1" />

@Fresa
Copy link
Copy Markdown

Fresa commented May 27, 2019

Is it really "rulename"? It looks like it parses "name":

@snakefoot
Copy link
Copy Markdown
Contributor Author

snakefoot commented May 27, 2019 via email

@304NotModified
Copy link
Copy Markdown
Member

304NotModified commented May 27, 2019

See

case "RULENAME":
ruleName = childProperty.Value; // Legacy Style

@snakefoot snakefoot deleted the LoggingConfigurationReader branch April 4, 2020 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) feature needs documentation on wiki refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants