Just starting using Serilog + ElasticSearch and was wondering if there is an elegant way to log a params
object array in one log entry. So far the only way I have been able to manage it is looping through each params
which creates a separate log entry for each one. Any way to combine them into one log entry?
Thanks!
Sample:
public static void MethodEntry<T>(string methodName, params object[] parameters)
{
if (parameters.Length > 0)
foreach (var param in parameters) // Will create parameters.Length number of log entries
Log.ForContext(typeof(T)).Debug("Entering {MethodName} with {@Param}", methodName, param);
else
Log.ForContext(typeof(T)).Debug("Entering {MethodName}", methodName);
}
EDIT:
Sinks used:
- Serilog
- Serilog.Sinks.Elasticsearch (which includes The File, PeriodicBatching, & RollingFile Sinks)
- Couple Enrichers like Environment and ThreadId