empty properties or named 'holes'

77 views
Skip to first unread message

Nicolas Tenoutasse

unread,
Jun 1, 2016, 6:57:57 AM6/1/16
to Serilog
Hi,

not sure which word to use to speak about them, properties or names 'holes' like you say sometimes... first question: what is the proper name?

but I came accross another use case that has not been foreseen for what I see:
what happens when they are empty? of course there are more than one emptiness but let's stick to strings

if you try something like 
Log.Information("{action} {id}", "view", "");

my first thought was: will id be included or not?
since I don't recall that case being addressed in the doc, I couldn't know beforehand so I tried...
my second thought was, it won't be included...

if you try, you'll see it is included... 
But if you try to add a tag in seq, you get a slightly missplaced tag..

is there a reason it is included? or it is by default?

Nicolas
PS don't even try not to give less parameters like Log.Information("{action} {id}", "view");


nblum...@nblumhardt.com

unread,
Jun 1, 2016, 7:21:42 PM6/1/16
to Serilog
Hi Nicolas,

From the Serilog point of view, both "" and null are valid values for properties. A property with a null or empty value still 'exists' so to speak, it's not the same as there being no property to begin with.

The behavior surrounding missing/duplicated tags in message templates is all pretty deliberate - are you implementing a scenario that calls for some alternative behavior?

(Thanks for the tip regarding Seq property placement - just a run-of-the-mill CSS text baseline bug, will check it out.)

Regards,
Nick

nblum...@nblumhardt.com

unread,
Jun 1, 2016, 7:23:25 PM6/1/16
to Serilog
Regarding the naming - "named holes" are the little brace-delimited tokens in the message template syntax. Properties are what Serilog attaches to its events when it matches the names with values. You can definitely call the named holes "property names" and be quite correct as well. HTH!

Nicolas Tenoutasse

unread,
Jun 2, 2016, 4:30:54 AM6/2/16
to Serilog
Hhere is my particular scenario where an empty field shouldn't be output:
let's say that I want put in the log the user that does an action, nothing easier:
Log.Information("{User} verb", user);

but in my application, users can impersonate others, in that case I want to log both users
Log.Information("{User} {Impersonator} verb", user, impersonator);

So it would be nice if impersonator (the variable) is empty, that the property would disappear so that it is equivalent to the first statement.
I'm sure anybody can come up with a scenario where the other behaviour is more diserable, so maybe an option for properties (outputifermpty) is the best bet? 

Thanks,
Nicolas

nblum...@nblumhardt.com

unread,
Jun 2, 2016, 5:34:50 PM6/2/16
to Serilog
Thanks for the follow-up. It's a reasonable scenario but not one likely to be addressed in Serilog at this point (aiming to keep things simple/not have too many switches/toggles).

Something like:

Log.Information("{User} as {Impersonator} verb", user, impersonator ?? user);

is probably your best bet.

Regards,
Nick
Reply all
Reply to author
Forward
0 new messages