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

Add CompoundLayout #1551

Merged
merged 7 commits into from
Jul 23, 2016
Merged

Add CompoundLayout #1551

merged 7 commits into from
Jul 23, 2016

Conversation

luigiberrettini
Copy link
Contributor

@luigiberrettini luigiberrettini commented Jul 22, 2016

As per issue #1543 I added a CompoundLayout Layout to make it possible to use multiple nested heterogeneous layouts and create complex log entries.

Take as an example the following configuration:

<nlog>
  <targets>
    <target name='file' type='File' fileName='log.txt'>
      <layout type='CompoundLayout'>
        <layout type='SimpleLayout' text="myAmazingText: " />
        <layout type='JsonLayout'>
          <attribute name='time' layout='${longdate}' />
          <attribute name='level' layout='${level:upperCase=true}'/>
          <attribute name='nested' encode='false'  >
            <layout type='JsonLayout'>
              <attribute name='message' layout='${message}' />
              <attribute name='exception' layout='${exception}' />
            </layout>
          </attribute>
        </layout>
      </layout>
    </target>
  </targets>
  <rules>
  </rules>
</nlog>

Log entries would be like this:

myAmazingText: { "time": "2016-10-30 13:30:55.0000", "level": "INFO", "nested": { "message": "this is message", "exception": "test" } }

@304NotModified
Copy link
Member

\0/

@codecov-io
Copy link

codecov-io commented Jul 22, 2016

Current coverage is 76% (diff: 87%)

Merging #1551 into master will increase coverage by <1%

@@             master      #1551   diff @@
==========================================
  Files           269        270     +1   
  Lines         16266      16293    +27   
  Methods        2605       2611     +6   
  Messages          0          0          
  Branches       1769       1771     +2   
==========================================
+ Hits          12367      12393    +26   
- Misses         3487       3501    +14   
+ Partials        412        399    -13   

Sunburst

Powered by Codecov. Last update 698ca65...ff95156

@@ -1102,6 +1104,15 @@ private bool AddArrayItemFromElement(object o, NLogXmlElement element)
return false;
}

private object CreateArrayItemInstance(NLogXmlElement element, Type elementType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is OK, but maybe nice to add some (XML) comments.

@304NotModified
Copy link
Member

Looks good, added some notes!

@304NotModified
Copy link
Member

Any idea if we could test this case:

image

(CreateArrayItemInstance returning null)
See https://codecov.io/gh/NLog/NLog/compare/698ca65c2ea8ac508a13f8d49d0e1c3c7a012c5c...f6d0d4a92c528cfd97927222847ac8b81ad0de87

@304NotModified
Copy link
Member

I think we almost ready to merge this.

Can you add those on the wiki? Public is fine. Please add some examples and "introduced in NLog 4.3.6"

@luigiberrettini
Copy link
Contributor Author

I just added the documentation.

https://github.com/NLog/NLog/wiki/Layouts
(I suppose the NuGet badge will auto-update to 4.3.6 when you release it)

https://github.com/NLog/NLog/wiki/CompoundLayout

@304NotModified
Copy link
Member

304NotModified commented Jul 23, 2016

Great! Thanks!

An yes, the badge works automatically :)

@304NotModified
Copy link
Member

It's online!

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

Successfully merging this pull request may close these issues.

None yet

3 participants