Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Support for placeholders and structured logging in Epi



I have a log setup in EpiServer using EPi.Libraries.Logging.Serilog and I was trying to integrate it with Logstash / ElasticSearch and Kibana.  But unfortunately the ILogger interface provided by Epi (EPiServer.Logging) doesn't support the use of placeholders in the lLog method, and therefore the LoggerExtensions class (EPiServer.Logging.LoggerExtensions) doesn't support the placeholders in the logging methods (information, error, etc). 

By Placeholders I mean:

_logger.Information("This is a {test}", "my input to logstash"). 

It doesn't support '{test}' , which would make me have fields/properties in the generated json sent to logstash.

Any ideas of workaround or any implementation that could make this work?

Thanks in advance!


Jun 03, 2019 14:36

It doesn't work if you put _logger.Information($"This is a {test}", "my input to logstash")? Looks like your are not putting the '$' in front of the string.

Have a look at the  docs

Jun 04, 2019 9:47

Hi Jeroen,

no, it doesn't work with the $ as well. Like I said, Epi loggerExtensions doesn't support that kind of message template. 

Jun 04, 2019 11:38

The message is a string, so it supports interpolated strings as well. I use them all the time

Jun 04, 2019 12:19

Hi Jeroen,

do you mean in EPI and with _logger.Information for example?

Because when I try this it for example: 

_logger.Information($"{Test}", "123");

it gives compilation error saying "Cannot resolve symbol Test".

My purpose here is to have events/fields/properties logged differently for visualization in Kibana.

Thanks for the help, I appreciate it. 

Edited, Jun 04, 2019 12:56

in this case {Test} should be a variable, or a property of an object you have, or ...  So you will probably get that compilation error because 'Test' is not available

An example from Quicksilver:

_logger.Information($"Cart '{cart.Name}' for user '{cart.CustomerId}' is being deleted.");
Jun 04, 2019 13:46

Yeah, but what I want is a placeholder, not a variable.

If you have time you can check "structured logging" or event logging. 

That's more or less what I'm talking about.

Jun 04, 2019 14:00

You could create your own enricher for the things you need, if that's an option

Jun 04, 2019 14:20

Sounds good. Do you have an example/link to share?

Jun 04, 2019 14:36

You could have a look at these

Jun 04, 2019 14:44

Sounds good. Will take a look. Thanks.

Jun 04, 2019 14:47

For sites that use Application Insights (whether Episerver DXC or not), here is an article with a small demonstration. It is about logging and tracing (metadata and metrics) with Application Insights.

Jun 17, 2019 14:51
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.