-
Notifications
You must be signed in to change notification settings - Fork 151
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
Convert json array struct to object struct, Convenient to load configuration files according to the environment #293
Comments
Really like the idea of merging logging-rules. But the NLog rules needs to be evaluated in correct order, and MEL always performs sorting when dictionary Could one solve it by introducing something like rule-groups? (Here group-name "default" + "override")
By using "name" one can even override individual logging-rules, but one can also add additional logging-rules in nlog.dev.json. Not that experienced with appsettings.json. So any input is great. I just implemented json-support as a proof-of-concept. |
Peaked over the fence to our neighbor, and saw others doing this: "rules": {
"0": {
"logger": "*",
"minLevel": "Trace",
"writeTo": "all-file"
},
"1": {
"logger": "Microsoft.*",
"minLevel": "Info",
"final": true
},
"2": {
"logger": "*",
"minLevel": "Trace",
"writeTo": "own-console"
}
} So you can already do this with the current implementation: nlog.json "rules": {
"0": {
"logger": "*",
"minLevel": "Error",
"writeTo": "errorFile,errorEmail"
},
"1": {
"logger": "*",
"minLevel": "Debug",
"writeTo": "debugFile"
}
} nlog.dev.json (Overwrites rule-"0" and adds rule-"200"); "rules": {
"0": {
"logger": "*",
"minLevel": "Error",
"writeTo": "errorFile"
},
"200": {
"logger": "*",
"minLevel": "Debug",
"writeTo": "debugConsole"
}
} |
Btw. it is useful to use integer-values to ensure correct ordering of logging-rules. But one can also add extra details: "rules": {
"00_all-file": {
"logger": "*",
"minLevel": "Trace",
"writeTo": "all-file"
},
"01_blackhole": {
"logger": "Microsoft.*",
"minLevel": "Info",
"final": true
},
"02_own-console": {
"logger": "*",
"minLevel": "Trace",
"writeTo": "own-console"
}
} |
Thank you very much, it solved my problem. |
@czd890 Have updated the wiki with the extra details: https://github.com/NLog/NLog.Extensions.Logging/wiki/Json-NLog-Config Please feel free to edit. If I have forgotten important details, or you have some nice tips. |
If
NLog:rules
section is array, Loading the configuration file according to the environment needs to rewrite all theNLog:rules
section, Maybe use object replace array struct.Json config file rules, Please See Load JSON based NLog config
nlog.json
nlog.dev.json
The text was updated successfully, but these errors were encountered: