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

JsonLayout #481

Merged
3 commits merged into from
Dec 29, 2014
Merged

JsonLayout #481

3 commits merged into from
Dec 29, 2014

Conversation

vladikk
Copy link
Contributor

@vladikk vladikk commented Dec 28, 2014

A new layout that renders log events as structured JSON documents.
The implementation and setup are similar to the CsvLayout:

<target name="jsonFile" xsi:type="File" fileName="${logFileNamePrefix}.json">
      <layout xsi:type="JsonLayout">
              <attribute name="time" layout="${longdate}" />
              <attribute name="level" layout="${level:upperCase=true}"/>
              <attribute name="message" layout="${message}" />
              <attribute name="callsite" layout="${callsite:includeSourcePath=true}" />
              <attribute name="stacktrace" layout="${stacktrace:topFrames=10}" />
              <attribute name="exception" layout="${exception:format=ToString}"/>
       </layout>
</target>

@ghost
Copy link

ghost commented Dec 28, 2014

Thanks for the pull request I'll take a look at it

ghost pushed a commit that referenced this pull request Dec 29, 2014
@ghost ghost merged commit e485413 into NLog:master Dec 29, 2014
@ghost ghost added the feature label Dec 29, 2014
@ghost ghost added this to the 4.0 milestone Dec 29, 2014
@grbinho
Copy link
Contributor

grbinho commented May 27, 2015

Hi,

First of all, I think this is a great addition to NLog.

I have a question about nested JSON objects.

Is this intended only of key value pairs? Can we nest our own JSON? Something like a property bag that we serialize and add to event-context.

As far as i can see all attributes are not json-encoded. That means that attributes that are already valid JSON will get escaped where that is not needed or am i missing something?
It would be beneficial if encoding is a property on the attribute.

Best,
Ivan

@304NotModified
Copy link
Member

Hi,

What do you mean with :

As far as i can see all attributes are not json-encoded.

So far I know, everything is encoded with the JsonEncodeLayoutRendererWrapper.

I think other objects besides key-value pairs would be nice. Please create a new issue for this feature request if you like. Also an (config) example would be nice.

@grbinho
Copy link
Contributor

grbinho commented May 27, 2015

Sorry, tipo :)

I have forked the project and implemented a small change.

I have added encode attribute on JsonAttribute so that user can control if output should be encoded. Setting this to false will enable user to add arbitrary JSON into context.

I'm still missing some tests, but can eventually create a pull request if you find it interesting.

@304NotModified
Copy link
Member

I find it interesting 👍

PR is welcome, but I does need some unit tests (and examples for the documentation)

@grbinho
Copy link
Contributor

grbinho commented May 27, 2015

Ok. Great, I will try to get that done as soon as possible.

@304NotModified 304NotModified added the documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) label Jan 14, 2018
This pull request was closed.
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 json / json-layout needs documentation on wiki
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants