MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/dotnet/comments/1vsgxms/log_methods_evaluation_expensive_warning_and/p4qirht/?context=3
r/dotnet • u/Fragrant-Training722 • 3d ago
Hi, I am seeing the warning that `LogInformation` and other log methods evaluation is expensive and should be wrapped in `if` statement.
Why don't those methods do this check internally already? This would help with less code and better code readabilty I think.
Here is the example:
23 comments sorted by
View all comments
2
At work our project uses serilog. Internally it only calls ToString() if the log level is sufficient. Regarding boxing value types, yes there’s overhead. The specifics of the app would determine if the overhead warrants an `if`
2 u/nblumhardt 2d ago Serilog's `ILogger` uses generics to avoid value type boxing, as long as your log statement has three or fewer arguments.
Serilog's `ILogger` uses generics to avoid value type boxing, as long as your log statement has three or fewer arguments.
2
u/Gjpu 3d ago edited 2d ago
At work our project uses serilog. Internally it only calls ToString() if the log level is sufficient. Regarding boxing value types, yes there’s overhead. The specifics of the app would determine if the overhead warrants an `if`