Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NLogLoggingConfiguration - Added support for default-wrapper, default-target-parameter & autoReload #283

Merged
merged 12 commits into from
Apr 27, 2019

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Apr 3, 2019

and default-target-parameters:

Example JSON-config:

{
    "NLog": {
        "targets": {
            "default-wrapper": {
                "type": "AsyncWrapper",
                "overflowAction": "Block"
            },
            "default-target-parameters": {
                "console": {
                    "error": "true",
                },
                "file": {
                    "encoding": "utf-8",
                },
            },
            "console": {
                "type": "Console"
            },
            "debugLog": {
                "type": "File",
                "fileName": "c:/temp/console-debug.log"
            },
            "errorLog": {
                "type": "File",
                "fileName": "c:/temp/console-error.log"
            }
        },
        "rules": [
            {
                "logger": "*",
                "minLevel": "Trace",
                "writeTo": "debugLog,Console"
            },
            {
                "logger": "*",
                "minLevel": "Error",
                "writeTo": "errorLog"
            }
        ]
    }
}

@codecov
Copy link

codecov bot commented Apr 3, 2019

Codecov Report

Merging #283 into master will increase coverage by 0.33%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #283      +/-   ##
==========================================
+ Coverage   70.45%   70.79%   +0.33%     
==========================================
  Files          12       12              
  Lines         958      976      +18     
  Branches      170      178       +8     
==========================================
+ Hits          675      691      +16     
  Misses        221      221              
- Partials       62       64       +2
Impacted Files Coverage Δ
...ensions.Logging/Config/NLogLoggingConfiguration.cs 85.1% <90.9%> (+0.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f33779...0c645f6. Read the comment docs.

@snakefoot
Copy link
Contributor Author

snakefoot commented Apr 3, 2019

@304NotModified One more bullet in the chamber. Do we have other frequently used config-features?

@304NotModified
Copy link
Member

Have to check. One in mind, Do we support async=true on targets level?

@304NotModified
Copy link
Member

304NotModified commented Apr 3, 2019

I was thinking the default-wrapper etc should be outside the wrappers (so next to it, instead of inside). Not sure of that's problematic (could image that!). If so, then is not a problem

@snakefoot
Copy link
Contributor Author

snakefoot commented Apr 3, 2019

I was thinking the default-wrapper etc should be outside the wrappers (so next to it, instead of inside).

When you say "wrappers" then you mean "targets"-section ? For xml-config then default-wrapper lives inside the targets-element.

Xml-config has support for multiple "targets"-sections with different "default-wrapper" and "default-target-parameters". Right now I'm focusing on a single "targets"-section since 99 out 100 are doing this.

@snakefoot
Copy link
Contributor Author

snakefoot commented Apr 3, 2019

Do we support async=true on targets level?

I was hoping one could just do this:

            "default-wrapper": {
                "type": "AsyncWrapper"
            },

@304NotModified
Copy link
Member

When you say "wrappers" then you mean "targets"-section ? For xml-config then default-wrapper lives inside the targets-element.

Yes and yes I know : 👼

@snakefoot
Copy link
Contributor Author

snakefoot commented Apr 3, 2019

@304NotModified Yes and yes I know

I'm trying to make the JSON and XML config match as much as possible, unless there is a more natural JSON-formating (Ex. making use of JSON-dictionary-keys)

I feel that default-target-parameters and default-wrapper belongs inside the targets-section.

Maybe one day JSON-config will be used with a targets-sections-array (very exotic and not sure if it is support by the current logic)

        "targets": [
            {
               "console": {
                   "type": "Console"
               }
            },
            {
                "default-wrapper": {
                   "type": "AsyncWrapper",
                   "overflowAction": "Block"
                },
                "debugLog": {
                   "type": "File",
                   "fileName": "c:/temp/console-debug.log"
                }
            }
        ]

@304NotModified
Copy link
Member

I'm trying to make the JSON and XML config match as much as possible

Why is that? As xml and json have different conventions and limitations. I really prefer natural json over xml-with-json-sause.

Of course, if this is too difficult in the code (for now), that's fine.

@304NotModified
Copy link
Member

PS. In the json there is now a possible name clash, and not in the xml version.

@snakefoot
Copy link
Contributor Author

snakefoot commented Apr 3, 2019

I really prefer natural json over xml-with-json-sause.

I feel that I have been very diligent in trying to make the Json-format as pretty as possible. And the reason for making it close to xml-naming and xml-layout is because of documentation reuse. Allows the user to quickly map back and forth (And use the existing wiki). If you feel that the my choices in the Json-format are completely wack then we should probably rollback everything. Then you can start over.

PS. In the json there is now a possible name clash, and not in the xml version.

Would be very obfuscating if someone started to name their actual targets "default-wrapper" or "default-target-parameters". Even in xml-version.

@304NotModified
Copy link
Member

I feel that I have been very diligent

Yes you are, sorry for the used words. Its not meant unkind.

@304NotModified
Copy link
Member

How much work would it be to get the new elements (default-wrapper,default-target-parameters) on level up?

e.g.

{
    "NLog": {
         "default-wrapper": {
            "type": "AsyncWrapper",
            "overflowAction": "Block"
         },
         "default-target-parameters": {
             "console": {
                 "error": "true",
             },
             "file": {
                 "encoding": "utf-8",
             },
         },
        "targets": {
           
            "console": {
                "type": "Console"
            },
            "debugLog": {
                "type": "File",
                "fileName": "c:/temp/console-debug.log"
            },
            "errorLog": {
                "type": "File",
                "fileName": "c:/temp/console-error.log"
            }
        },
        "rules": [
            {
                "logger": "*",
                "minLevel": "Trace",
                "writeTo": "debugLog,Console"
            },
            {
                "logger": "*",
                "minLevel": "Error",
                "writeTo": "errorLog"
            }
        ]
    }
}

That would make this change even better IMO

@snakefoot
Copy link
Contributor Author

snakefoot commented Apr 14, 2019

get the new elements (default-wrapper,default-target-parameters) on level up?

They are not new elements. They exists already in NLog-config-engine. Just feeding them properly so NLog can understand the Json-version.

That would make this change even better IMO

Everything is possible with code. It is just gonna be very ugly. Have to inject the "special" children ( "default-wrapper" + "default-target-parameters") from the top-element into its targets-child.

@snakefoot
Copy link
Contributor Author

@304NotModified After having looked the code. Then I think I will let you have the honors of trying to bend the LoggingConfigurationParser to your will.

@codecov-io
Copy link

codecov-io commented Apr 14, 2019

Codecov Report

Merging #283 into master will increase coverage by 4.46%.
The diff coverage is 95.23%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #283      +/-   ##
=========================================
+ Coverage   69.23%   73.7%   +4.46%     
=========================================
  Files          11      12       +1     
  Lines         933    1080     +147     
  Branches      165     189      +24     
=========================================
+ Hits          646     796     +150     
+ Misses        226     220       -6     
- Partials       61      64       +3
Impacted Files Coverage Δ
...ensions.Logging/Config/NLogLoggingConfiguration.cs 93.43% <95.23%> (+9.22%) ⬆️
...g.Extensions.Logging/Logging/NLogLoggerProvider.cs 75.38% <0%> (-1.54%) ⬇️
...tensions.Hosting/Extensions/ConfigureExtensions.cs 92% <0%> (ø)
src/NLog.Extensions.Logging/Logging/NLogLogger.cs 81.54% <0%> (+1.1%) ⬆️
...tensions.Logging/Extensions/ConfigureExtensions.cs 14.51% <0%> (+6.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b9b021...d620865. Read the comment docs.

@304NotModified
Copy link
Member

@304NotModified After having looked the code. Then I think I will let you have the honors of trying to bend the LoggingConfigurationParser to your will.

-> snakefoot#7

@304NotModified
Copy link
Member

note: I think there is something wrong with the casing, #283 (comment)

shows "targets", but It's implemented as "Targets"?

Default wrapper and Default-target-parameters on top level
@snakefoot
Copy link
Contributor Author

snakefoot commented Apr 27, 2019

Sure hope everything is case-insensitive, else it would become nightmare.

@snakefoot
Copy link
Contributor Author

Lots of CodeFactor issues now after merge :)

@304NotModified
Copy link
Member

Lots of CodeFactor issues now after merge :)

I will fix that (soon)

@304NotModified 304NotModified self-assigned this Apr 27, 2019
@304NotModified
Copy link
Member

Sure hope everything is case-insensitive, else it would become nightmare.

do we need to check/test that?

@snakefoot
Copy link
Contributor Author

do we need to check/test that?

Should be handled automatically by LoggingConfigurationParser. Unless there is some case-sensitive logic in NLogLoggingConfiguration.

@304NotModified
Copy link
Member

Should be handled automatically by LoggingConfigurationParser. Unless there is some case-sensitive logic in NLogLoggingConfiguration.

changing NLogLoggingConfigurationTests, e.g. memoryConfig["NLog:Targets:file:type"] to memoryConfig["NLog:targets:file:type"] fails the test, is that correct?

@snakefoot
Copy link
Contributor Author

According to:

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2

Keys are case-insensitive. For example, ConnectionString and connectionstring are treated as equivalent keys.

So calls to GetSection should work correctly independent of casing.

@snakefoot
Copy link
Contributor Author

changing NLogLoggingConfigurationTests, e.g. memoryConfig["NLog:Targets:file:type"] to memoryConfig["NLog:targets:file:type"] fails the test, is that correct?

Nope it should not fail.

@304NotModified
Copy link
Member

Nope it should not fail.

I see the issue I think

@304NotModified
Copy link
Member

37abc56

but maybe doubting if this is a good change

@snakefoot
Copy link
Contributor Author

snakefoot commented Apr 27, 2019

I can change the casing without tests breaking. But running on my clean PR without your changes (And without case-insensitive-key-comparer on dictionary)

@snakefoot
Copy link
Contributor Author

But since you have identified a possible issue with breaking case-insensitivity, then it could be a good idea to have a test of this.

@304NotModified
Copy link
Member

304NotModified commented Apr 27, 2019

yes, added some (in the current tests 👼 )

and this goes wrong: (not committed)

 memoryConfig["NLog:rules:0:logger"] = "*";

(lower case rules)

this works

memoryConfig["nlog:Rules:0:logger"] = "*";

(lower case nlog)

@304NotModified
Copy link
Member

and this goes wrong: (not committed)

 memoryConfig["NLog:rules:0:logger"] = "*";

(lower case rules)

Any idea why? Just checked the NLog dev branch, but don't see the issue 123.

@snakefoot
Copy link
Contributor Author

and this goes wrong: memoryConfig["NLog:rules:0:logger"] = "*";

Think you are now testing the test. Make sure to have all entries to have the same casing. Ex:

            memoryConfig["NLog:rules:0:logger"] = "*";
            memoryConfig["NLog:rules:0:minLevel"] = "Trace";
            memoryConfig["NLog:rules:0:writeTo"] = "File,Console";

@304NotModified
Copy link
Member

ow otherwise those are separate sections? (rules and Rules)?

@304NotModified 304NotModified added this to the 1.5 milestone Apr 27, 2019
@snakefoot
Copy link
Contributor Author

Could you change your "casing"-test so all entries are using the same casing ?

@304NotModified
Copy link
Member

But it won't break anything?

@snakefoot
Copy link
Contributor Author

But it won't break anything?

Not sure I understand. Anyway will create a new PR when this is merged, since support for KeepVariablesOnReload is still missing

@304NotModified
Copy link
Member

Could you change your "casing"-test so all entries are using the same casing ?

done

@304NotModified 304NotModified changed the title NLogLoggingConfiguration - Added support for default-wrapper and Default-target-parameter NLogLoggingConfiguration - Added support for default-wrapper, default-target-parameter & AutoReload Apr 27, 2019
@304NotModified 304NotModified changed the title NLogLoggingConfiguration - Added support for default-wrapper, default-target-parameter & AutoReload NLogLoggingConfiguration - Added support for default-wrapper, default-target-parameter & autoReload Apr 27, 2019
@304NotModified 304NotModified merged commit cef73eb into NLog:master Apr 27, 2019
@304NotModified
Copy link
Member

merged :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants