-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
XmlLayout - Render LogEventInfo.Properties as XML #2670
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #2670 +/- ##
======================================
- Coverage 80% 80% -<1%
======================================
Files 331 333 +2
Lines 25641 26034 +393
Branches 3321 3404 +83
======================================
+ Hits 20560 20844 +284
- Misses 4145 4227 +82
- Partials 936 963 +27 |
Still work-in-progress |
nice! |
Now I think it is ready for review. |
8dae8cf
to
d8dfb39
Compare
33182b8
to
9cdfa86
Compare
src/NLog/Internal/XmlHelper.cs
Outdated
{ | ||
if (i == 0 && (chr == 'x' || chr == 'X') && xmlElementName.Length >= 3) | ||
{ | ||
if (char.ToLowerInvariant(xmlElementName[1]) == 'm' && char.ToLowerInvariant(xmlElementName[2]) == 'l') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we testing here? The element <xml
? And it will be <_xml
?
Please add this to the code comments, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a very nice comment at the top explaining the rules for XML-element-names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add an unit test for this?
[Layout("XmlLayout")] | ||
[ThreadAgnostic] | ||
[ThreadSafe] | ||
public class XmlLayout : Layout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we implement the Interface IIncludeContext
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like JsonLayout, then XmlLayout doesn't include IncludeNdc and IncludeNdlc as properties.
/// Determines wether or not this attribute will be Json encoded. | ||
/// </summary> | ||
/// <docgen category='XML Attribute Options' order='100' /> | ||
public bool Encode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe default it to true, as 2 of the 3 ctors set it to true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is true, as it gets the default value from XmlEncodeLayoutRendererWrapper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great! Would be nice if we could add some more unit tests for it.
I could help on that, but I'm not sure for every case how to cover it.
PS: im trying create a codecov report for 3d7f3ee
src/NLog/Layouts/XmlLayout.cs
Outdated
RenderXmlFormattedMessage(logEvent, target); | ||
if (target.Length == orgLength && IncludeEmptyValue && !string.IsNullOrEmpty(ElementName)) | ||
{ | ||
target.Append('<'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any idea if we could add an unit test for this case?
src/NLog/Layouts/XmlLayout.cs
Outdated
int beforeAttribLength = sb.Length; | ||
if (!RenderAppendXmlAttributeValue(attrib, logEvent, sb, sb.Length == orgLength)) | ||
{ | ||
sb.Length = beforeAttribLength; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any idea if we could add an unit test for this case?
src/NLog/Layouts/XmlLayout.cs
Outdated
string propNameElement = null; | ||
if (_propertiesElementNameHasFormat) | ||
{ | ||
propNameElement = XmlHelper.XmlConvertToStringSafe(propName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any idea if we could add an unit test for this case?
} | ||
else | ||
{ | ||
sb.Append('>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any idea if we could add an unit test for this case?
src/NLog/Internal/XmlHelper.cs
Outdated
{ | ||
if (i == 0 && (chr == 'x' || chr == 'X') && xmlElementName.Length >= 3) | ||
{ | ||
if (char.ToLowerInvariant(xmlElementName[1]) == 'm' && char.ToLowerInvariant(xmlElementName[2]) == 'l') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add an unit test for this?
{ | ||
if (chr == '_') | ||
{ | ||
sb?.Append(chr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add an unit test for this?
src/NLog/Internal/XmlHelper.cs
Outdated
sb = new StringBuilder(xmlElementName.Length); | ||
if (i > 1) | ||
sb.Append(xmlElementName, 0, i - 1); | ||
if (i == 0 && char.IsWhiteSpace(chr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add an unit test for this?
You can have as many unit-test that you like, just a matter of work-hours. Prefer to have agreement on API before starting to lock things down with unit-tests. But happy you like it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can have as many unit-test that you like, just a matter of work-hours.
yes, but then no force-push please.
Prefer to have agreement on API before starting to lock things down with unit-test
I'm happy with the design 👍 but there are some small naming things i'm doubting about. Added them as comments
Maybe we should move to a separate XML serializer class in the future, although 3rd party XML serializes aren't common
/// Auto indent and create new lines | ||
/// </summary> | ||
/// <docgen category='XML Options' order='10' /> | ||
public bool IndentXml { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just "Indent"
@snakefoot could you please resolve the merge conflict? Thanks! |
d95987c
to
d174e55
Compare
* XmlLayout - Render LogEventInfo.Properties as XML (Ex. SQL XML Column) * Handle self-referencing types * XmlLayout - Render LogEventInfo.Properties as XML (More test coverage) * XmlLayout - Render LogEventInfo.Properties as XML (Support for singleton tag) * XmlLayout - Render LogEventInfo.Properties as XML (Xml config in unit test) * XmlLayout - Render LogEventInfo.Properties as XML (Less flexible, easier to use) * XmlLayout - Renamed NodeName to ElementName * XmlLayout - Fixed XML comments * XmlLayout - Added support for MutableUnsafe * XmlLayout - Added support for MutableUnsafe (Refactor) * XmlLayout - Render LogEventInfo.Properties as XML (Optimize for XmlEncode = false) * XmlLayout - Render LogEventInfo.Properties as XML (No need for message template, yet) * XmlLayout - Render LogEventInfo.Properties as XML (Optimize for XmlEncode = false) * consts, c# 7 * deduplicate * deduplicate properties rendering * attrib -> attributes * small improvements * XmlLayout - Removed unnecessary allocation of yield state-machine * XmlLayout - Test proposal * Added test (fails) * Added test (succeeds) * Added test (succeeds) * Added test (fails) * Added test (fails) * Added test (succeeds) * XmlLayout - Fixed test of IncludeEmptyValue, and removed newline issues * XmlLayout - Added unit test with encoding of element-names
Started working on https://github.com/NLog/NLog/wiki/XmlLayout |
@snakefoot this could be helpful: |
updated the xml layout. Added some more sections, not sure if it's better. Feel free to restructure |
bit stange that attribute has "name" and element has "ElementName " 👼 |
Think it was your decision. Don't mind changing it. |
Then maybe its my mistake 😂 |
Created #3137 as example of possible rename. |
@snakefoot I'm happy with the docs now, are you also? (https://github.com/NLog/NLog/wiki/XmlLayout) One thing I'm doubting of, the first "definition" is a bit strange: It's now a combo of a definition ( Should we convert it to an example or a definition? |
@304NotModified Made some updates to the Wiki-page for XmlLayout: https://github.com/NLog/NLog/wiki/XmlLayout (Like that it is an example) |
Ex. SQL XML Column
Ex. SMTP mails with advanced XHTML-formatting (colors etc):
msg.BodyFormat = MailFormat.Html;