Using ILogger<T>, is there a way to add log properties in addition to the ones covered by the message template?
For example:
_logger.LogInformation("Order {OrderNumber} was registered.", orderNumber);
// Appending extra information to this log entry would be neat:
// OrderOriginSystem = InStoreSupport
// Supervisor = Duncan P.
// StoreLocationCode = ca-north-12
I know Serilog allows various approaches for appending additional properties to log statements, and these seem to play nice with ILogger<T>, e.g.:
using (LogContext.PushProperty("OrderOriginSystem ", orderOriginSystem))
using (LogContext.PushProperty("Supervisor", supervisor))
using (LogContext.PushProperty("StoreLocationCode", slc))
{
_logger.LogInformation("Order {OrderNumber} was registered.", orderNumber);
}
But I'd like to avoid having to commit to Serilog directly in my code, and hope to instead rely on ILogger<T> throughout.
Is there some trick I've missed?