question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Named parameters with not only alphanumeric symbols are ignored

See original GitHub issue

Does this issue relate to a new feature or an existing bug?

  • Bug
  • New Feature

What version of Serilog is affected? Please list the related NuGet package.

2.8.0

What is the target framework and operating system? See target frameworks & net standard matrix.

  • netCore 2.0
  • netCore 1.0
  • 4.7
  • 4.6.x
  • 4.5.x

Please describe the current behavior?

Log.Information("Error {Rpc.Error} occured", "boom");

renders to Error {Rpc.Error} occured

Please describe the expected behavior?

Error "boom" occured


Relates to #404

I discovered that this is due to IsValidInPropertyName method inside ParsePropertyToken:

for (var i = 0; i < propertyName.Length; ++i)
{
      var c = propertyName[i];
      if (!IsValidInPropertyName(c))   <--- ???
           return new TextToken(rawText, first);
}

I originally used LogContext.PushProperty("Rpc.Error", "boom") and everything worked fine. I am interested in the question - why, when parsing a message template, knowingly narrow the set of valid characters of property name if the neighboring api (Push) allows you to add properties with any characters? This asymmetry led to an error when I moved the property name inside the format string and began to pass the value of the property in the params.

I read #404, but I don’t understand the motivation. First, this is no structured data, just plain string.

Dots within property names themselves aren’t supported by many target sinks, so we chose the lowest common denominator here.

Second, I use Console and Kafka sink which both support dots in property names. However, this talk is not even about the dots. The template string does not work if you use any character other than an alphanumeric character or underscore - :, -, etc. What problem do you solve when you talk about lowest common denominator? And here I come back to the fact that Push allows you to pass an arbitrary property name (and that’s cool). Therefore, as I see it, all this concern for the lowest common denominator does not make sense.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:21 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
otto-gebbcommented, Oct 8, 2020

@nblumhardt that helps indeed, thanks a lot!

I came to the same idea, but my implementation of it was rather cumbersome, I did the replacement in a class derived from Serilog.Formatting.Elasticsearch.ExceptionAsObjectJsonFormatter.

1reaction
sungam3rcommented, Nov 13, 2019

or a structured property Rpc with field Error

Structuredeness of a property is determined not by its name, but is specified by service characters - @, $.

Would multiple Rpc.* properties that appear in one message be merged into a single structured value?

Again, structuredeness of a property is determined not by its name, but is specified by service characters - @, $.

I see that you are referring to a grammar in which Name does not allow dots and other syntactic characters. Whatever the specification is, it exists and it is much more difficult to change it than implementation, in this I agree with you.

Nevertheless, I see that there is IMessageTemplateParser interface. MessageTemplateCache gets it in ctor but in fact MessageTemplateCache is initialized using a specific parser implementation in MessageTemplateProcessor:

 readonly MessageTemplateCache _parser = new MessageTemplateCache(new MessageTemplateParser());

I suggest passing another parameter of the type IMessageTemplateParser into MessageTemplateProcessor constructor and create MessageTemplateCache with it. This will require making the IMessageTemplateParser public interface and moving out of Core namespace (by the way, which one?). MessageTemplate is already public so I don’t think there will be problems.

Next, MessageTemplateProcessor is created inside LoggerConfiguration where one can easily add a new configuration property to set the parser like LoggerSinkConfiguration WriteTo does. Thus, backward compatibility will not be violated, and those customers who need to use additional characters (dot, hyphen etc) in the message template will get this opportunity. They explicitly specify this in the provided configuration.

Will you accept such a PR?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to ignore cases and considering alphanumerical ...
3 Answers. You could remove all non alphanumeric characters from the string before checking to see if it's a palindrome. For example: public ......
Read more >
Template error: variable names in Fn::Sub syntax must ...
Template error: variable names in Fn::Sub syntax must contain only alphanumeric characters, underscores, periods, and colons when using !Sub with bash.
Read more >
Why does 'sort' ignore special characters, like the asterisk?
I'm not specifying any option to ignore non-alphabetic characters or anything. Just sort dict > out . My version of sort comes from...
Read more >
Parameter field
An asterisk indicates that the parameter will be ignored. The other parameters listed result in a JCL error and job failure.
Read more >
Define and reference variables in AWSTOE - EC2 Image Builder
The name can only contain alphanumeric characters (a-z, A-Z, 0-9), ... Parameter names that are not found in the YAML component document are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found