elasticsearch - Using C# params with serilog -
just starting using serilog + elasticsearch , wondering if there elegant way log params
object array in 1 log entry. far way have been able manage looping through each params
creates separate log entry each one. way combine them 1 log entry?
thanks!
sample:
public static void methodentry<t>(string methodname, params object[] parameters) { if (parameters.length > 0) foreach (var param in parameters) // create parameters.length number of log entries log.forcontext(typeof(t)).debug("entering {methodname} {@param}", methodname, param); else log.forcontext(typeof(t)).debug("entering {methodname}", methodname); }
edit:
sinks used:
- serilog
- serilog.sinks.elasticsearch (which includes file, periodicbatching, & rollingfile sinks)
- couple enrichers environment , threadid
if know specific type of sender object can use following feature of serilog avoid logging of not required information:
log.logger = new loggerconfiguration() .destructure.bytransforming<your_sender_type>( r => new { firstvalue = r.firstvalue, secondvalue = r.secondvalue }) .writeto ....
more logging structured data can find in official documentation serilog structured data
Comments
Post a Comment