I have an object with several properties that relate to an event that just occurred on my website.
I want to log this event, and for each of its properties to appear in Seq - as properties. However want to omit most of the properties from the actual log message text - so I don't want them in the message template. v
If I do this:
var logInfo= new LogInfo() {Foo = 1, Bar= "Pending"};
logger.Information("{@event}", logInfo);
The only property that lights up in Seq directly against the log, is the @event property. It actually looks like this:
So I tried this:
var enricher = new DnnLogInfoEnricher(logInfo);
using (LogContext.PushProperties(enricher))
{
Log.Logger.Information("Event: {logInfo}", logInfo.LogTypeKey, logInfo.Exception);
}
But my concern with this approach, is that as this method is going to fire an enormous number of times, I'd prefer not to have to create a new enricher object instance each time - as I like to keep the number of objects being created generally as low as possible.. Just because I am concerned about GC implications (perhaps my concerns are unfounded?).
Is this the correct / right way to achieve what I want (i.e using the enricher) or am I missing something?
Cheers!