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

Support layouts (e.g. JSON) and inner text in <variable> #3459

Merged
merged 1 commit into from
Jun 8, 2019

Conversation

304NotModified
Copy link
Member

@304NotModified 304NotModified commented Jun 7, 2019

fixes #1577 and fixes #1312

@304NotModified
Copy link
Member Author

@snakefoot I have the idea you don't like this change 👼

@304NotModified 304NotModified changed the title Support layouts and inner text in <variable> Support layouts (e.g. JSON) and inner text in <variable> Jun 7, 2019
@304NotModified 304NotModified added breaking change Breaking API change (different to semantic change) feature nlog-configuration labels Jun 7, 2019
@304NotModified 304NotModified added this to the 5.0 (new) milestone Jun 7, 2019
@snakefoot
Copy link
Contributor

snakefoot commented Jun 8, 2019 via email

@304NotModified 304NotModified merged commit 3ea1431 into dev Jun 8, 2019
@repo-ranger repo-ranger bot deleted the variables-support-inner branch June 8, 2019 11:13
@snakefoot
Copy link
Contributor

snakefoot commented Jun 8, 2019 via email

@304NotModified
Copy link
Member Author

thanks for the feedback -> #3462

@snakefoot
Copy link
Contributor

snakefoot commented Jun 8, 2019 via email

@304NotModified
Copy link
Member Author

The value property could just return null in the case of JSON

@snakefoot
Copy link
Contributor

snakefoot commented Jun 9, 2019 via email

@304NotModified
Copy link
Member Author

'Value' isn't xml specific?

Anyway, do you have a proposal how to solve this different? One way or another, this needs a breaking change.

@snakefoot
Copy link
Contributor

snakefoot commented Jun 9, 2019

Yes it will always be a breaking change for the Variables-container. Anyway created #3466

@snakefoot
Copy link
Contributor

snakefoot commented Jun 10, 2019

Btw. could be nice if one could make a static reference to a JsonLayout. So one is not required to use "${var:myjson}" but could just write:

    <variable name='myJson'>
        <layout type='JsonLayout'>
            <attribute name='short date' layout='${shortdate}' />
            <attribute name='message' layout='${message}' />
        </layout>
    </variable>
    <targets>
         <target type='file' name='myfile' layout='${myJson}' />
    <targets>

Then one could skip a dictionary lookup for every logevent-write. And one would be able to make use of optimizations like ThreadAgnostic.

@oskaremil
Copy link

Can I use

"variables": {
      "varDefaultLayout": {
          "type": "JsonLayout",
          "Attributes": [
            {
              "name": "timestamp",
              "layout": "${date:format=o}"
            }
            ]
        }
    },

and then

"targets": {
      "logfile": {
        "layout": "${varDefaultLayout}"

in my target when reading configuration from appsettings.json ?

@snakefoot
Copy link
Contributor

snakefoot commented May 10, 2020

Maybe add example to wiki-page, when NLog 5 is released:

NLog JsonLayout as NLog Config Variable Example

<nlog>
  <variable name="defaultJsonLayout" >
    <layout type="JsonLayout">
       <attribute name="message" value="${messsage}">
    </layout>
  </variable>
  <targets>
    <target name="debug" type="Debug" layout="${var:defaultJsonLayout}" />
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="debug" />
  </rules>
</nlog>

API

var newJsonLayout = new NLog.Layouts.JsonLayout() { IncludeAllProperties = true };
LogManager.Configuration.Variables["defaultJsonLayout"] = newJsonLayout;

@snakefoot
Copy link
Contributor

Updated wiki: https://github.com/NLog/NLog/wiki/Configuration-file#variables

@snakefoot snakefoot added the documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) label Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Breaking API change (different to semantic change) documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) feature needs documentation on wiki nlog-configuration XSD change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Support inner text in <variable> tags Allow: JsonLayout into a variable
3 participants