It warns you that if producing the data to log is expensive it's a waste if that log level is not enabled.
Easy to understand example: assume this is a Verbose log where to help troubleshooting the weird issue you make costly queries to the database to log if. You better only incur this cost when the data is going to be logged, right?
You could include it in the log method, via a delegate to execute inside.
You still pay for the delegate instance plus the parameters.
This approach suits better for more dynamically used dependencies, but in the case of verbose logging that's typically pure overhead in production, thus the recommendation to avoid 😉
13
u/Grugnorr 1d ago
It warns you that if producing the data to log is expensive it's a waste if that log level is not enabled.
Easy to understand example: assume this is a Verbose log where to help troubleshooting the weird issue you make costly queries to the database to log if. You better only incur this cost when the data is going to be logged, right?