serilog-metrics/serilog-metrics

Data is not inserted into message..

Closed this issue · 4 comments

using (Logger.BeginTimedOperation("Upload {SomeGuid}", propertyValues: someGuid))

The message that is logged is literally "Upload {SomeGuid}", there was no substitution and there was no SomeGuid in json.

The first parameter is the name of the operation and will be passed to the template as a property. It will not do nested substitution. So by design. Options are to just pass in the SomeGuid as a string (so concat it with "Upload ". Or override your own TimedOperation or pass in a different template.

Everywhere you specify a string to serilog it does substitution, I expected this to not be different. While it might be a name - that is output in the log, so would be cool if this was substituted too huh?

Thanks for response.

With Serilog you specify a message template and a collection of properties. Then those will be merged inside the template. What you enter here as the first parameter is actually one of those properties (the name, and not a template) and it will be merged inside the template.
So the Upload {SomeGuid} is not a template in this case.

In theory you can change the templates (pass those in as additional parameters) however the order of the properties passed into the logevent cannot be changed.

The TimedOperation is really a generic functionality to add timing metrics around a code block. You can decorate with a name and description and by default it will output the duration and optionally a warning if it exceeds a threshold. Anything more complicated would require a subclass.

Ah..."first parameter is a property"....