Support for placeholders and structured logging in Epi

Vote:
 

Hi,

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!

 

#204465
Jun 03, 2019 14:36
Vote:
 

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

#204488
Jun 04, 2019 9:47
Vote:
 

Hi Jeroen,

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

#204491
Jun 04, 2019 11:38
Vote:
 

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

#204492
Jun 04, 2019 12:19
Vote:
 

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. 

#204493
Edited, Jun 04, 2019 12:58
Vote:
 

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.");
#204495
Jun 04, 2019 13:46
Vote:
 

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.

#204496
Jun 04, 2019 14:00
Vote:
 

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

#204499
Jun 04, 2019 14:20
Vote:
 

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

#204500
Jun 04, 2019 14:36
Vote:
 

You could have a look at these

#204501
Jun 04, 2019 14:44
Vote:
 

Sounds good. Will take a look. Thanks.

#204502
Jun 04, 2019 14:47
Vote:
 

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.

#204772
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.