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

Allow: JsonLayout into a variable #1312

Closed
mccabela opened this issue Mar 18, 2016 · 3 comments · Fixed by #3459
Closed

Allow: JsonLayout into a variable #1312

mccabela opened this issue Mar 18, 2016 · 3 comments · Fixed by #3459
Assignees
Labels
breaking change Breaking API change (different to semantic change) feature nlog-configuration
Milestone

Comments

@mccabela
Copy link

NLog version 4.2.3 - .Net 4.5

Previously I used to store my layout in a variable and place that layout on the target. This allowed me to setup the defaultLayout once and share it across multiple targets.

e.g.

<!-- Setting the Variable -->
<variable name="defaultLayout" value="${iso8601dateformat}|${level:uppercase=true}|[${logger}]|[Thread-${threadid}]|[Machine-${machinename}]|${message}${onexception:${newline}EXCEPTION OCCURRED\:${exception:tostring:maxInnerExceptionLevel=5:innerFormat=tostring}}" />
<!-- Assigning the layout -->
      <target xsi:type="File" fileName="${logFilePath}trace.txt" layout="${defaultLayout}"
              maxArchiveFiles="100"
              archiveNumbering="Sequence"
              archiveAboveSize="${archiveFileAboveBytes}"
              archiveFileName="${logFilePath}archive/trace-{#####}.txt" />

I'm now moving my logging to use JsonLayout. Is it still possible to store the layout in a variable and assign it to a target?

If so can you please provide an example of how it can be done?

Thanks,

Lach

@304NotModified
Copy link
Member

I'm not sure if this would work, but maybe you can test (untested here)

<variable name="defaultLayout" >
  <layout type="JsonLayout">
    <attribute name="message" value="${messsage}">
  </layout>
</variable>

@mccabela
Copy link
Author

I tried and threw an exception "Expected value on " so I don't think it works :(

So it might need to be a feature request.

Thanks for the suggestion

@304NotModified 304NotModified changed the title Question: Is there a way to put a JsonLayout into a variable? Allow: JsonLayout into a variable Mar 28, 2016
@304NotModified
Copy link
Member

Checked the code, currently only SimpleLayouts are allowed. There was a good reason for this, not sure but I guess performance.

image

We should check if we could change this from SimpleLayout -> Layout.

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) feature nlog-configuration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants