I am trying to understand the performance impact of serilog destructuring operator, specifically to verify that destructure is not performed before the logger checks if the intended message can even be logged. For example, the following code:
var sensorInput = new { Latitude = 25, Longitude = 134 };
Log.Debug("Processing {@SensorInput}", sensorInput);
should not result in something like:
var tmp = destructure(sensorInput);
readonly bool _isDebug = Log.IsEnabled(LogEventLevel.Debug);
if (_isDebug) Log.Debug("Processing {var1}", tmp);
I did check the Serilog source code but I haven't found anything which would confirm the above is not happening - perhaps someone knows the relevant code?
Serilog will only apply destructuring if the event is enabled. Debug()
calls Write()
, which does a level check before any more work is performed.