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

Is it possible to do nested json configurations via complex variables or target-refs? #464

Closed
zahirtezcan-bugs opened this issue Dec 31, 2020 · 6 comments
Labels

Comments

@zahirtezcan-bugs
Copy link

Type:

  • Question

NLog.Extensions.Logging version: 1.6.5

I have tried multiple configurations but could not do 2 things:
1- Complex variables, for example a variable of type JsonLayout. I was only able to use simple variables such as a string.
2- Referencing other targets via target-ref or wrapped-target-ref properties within wrapper targets such as AsyncWrapper or RetryingWrapper.

Currently I am using copy-paste for long configurations. Is it possible to use complex variables or target-refs inside appsettings.json? Can you please direct me to an example or detailed documentation other than LoggingConfigurationParser code?

@snakefoot
Copy link
Contributor

snakefoot commented Jan 6, 2021

Think target-ref or wrapped-target-ref are difficult with appsettings.json as targets are re-ordered by name when Json (and not actual declared order, which works with xml Nlog.config). Difficult to make reference to an unknown target-name (because not yet parsed).

Support for having complete layouts in a variable is waiting for NLog 5.0 - NLog/NLog#3459, but maybe some preparation is needed in NLog.Extension.Logging.

@snakefoot
Copy link
Contributor

Created #465 to prepare for NLog 5.0

@zahirtezcan-bugs
Copy link
Author

Is there a way to infer target attributes/properties from variables then? I mean not one-by-one but as a template.

For example,

"variables": {
    "commonRetryingAttributes": {
        "retryDelayMilliseconds": ...
    }
}

...

"foo": {
    "type": "RetryingWrapper",
    "attributes" : "${var:commonRetryingAttributes}"
    "target": ...
}

@snakefoot
Copy link
Contributor

snakefoot commented Jan 8, 2021

No that would require some other JSON transformation logic. NLog Config Variables only contains a single NLog Layout.

@zahirtezcan-bugs
Copy link
Author

zahirtezcan-bugs commented Jan 8, 2021

One last question about this; would that be valid to refer current NLog configuration via ${configsetting:item=...} and .NET core configuration key syntax (parent:child:grandchild)?

For example:

"NLog": {
  ...
  "targets": {
    "foo": {
      ...
    }
    "bar": {
      ...
      "target": "${configsetting:item=NLog:targets:foo}"
    }
  }
  ...
}

@snakefoot
Copy link
Contributor

${configsetting} is used to lookup a single value from appsettings.json, which can be used to control the target-output.

It cannot be used to load an entire configuration-tree and inject at some other location.

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

No branches or pull requests

2 participants