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

added stringification support #160

Merged
merged 4 commits into from
Dec 11, 2019
Merged

added stringification support #160

merged 4 commits into from
Dec 11, 2019

Conversation

jonnybi
Copy link

@jonnybi jonnybi commented Nov 28, 2019

Added "force stringification" support as described in serilog documentation.

Copy link
Member

@nblumhardt nblumhardt left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for spotting this gap! Just had one comment.

@@ -78,6 +78,11 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
if (logger.BindProperty(property.Key.Substring(1), property.Value, true, out var destructured))
properties.Add(destructured);
}
else if (property.Key.StartsWith("$"))
{
if (logger.BindProperty(property.Key.Substring(1), property.Value?.ToString() ?? "null", true, out var stringified))
Copy link
Member

Choose a reason for hiding this comment

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

Substituting in the text null will be inconsistent with Serilog here, I think. We should just pass null if property.Value is null.

@nblumhardt
Copy link
Member

@jonnybi hi! I just spotted one more place where we special-case @, which I think should also accept $ for the sake of consistency:

https://github.com/serilog/serilog-extensions-logging/blob/dev/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerScope.cs#L75

@jonnybi
Copy link
Author

jonnybi commented Nov 30, 2019

@nblumhardt thx for spotting this. i will check it

@@ -78,6 +78,11 @@ public void EnrichAndCreateScopeItem(LogEvent logEvent, ILogEventPropertyFactory
destructureObject = true;
}

if (key.StartsWith("$"))
{
key = key.Substring(1);
Copy link
Member

Choose a reason for hiding this comment

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

The value would also have to be ToString()ed in order for this to take effect.

Copy link
Author

Choose a reason for hiding this comment

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

sry, i was a little too fast. Fixed it again and added a unit test.

@nblumhardt nblumhardt merged commit 6152c32 into serilog:dev Dec 11, 2019
@nblumhardt
Copy link
Member

Thanks! 👍

@nblumhardt nblumhardt mentioned this pull request Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants