iotedge-lorawan-starterkit icon indicating copy to clipboard operation
iotedge-lorawan-starterkit copied to clipboard

Logging statements execute a lot of work if log level is not enabled

Open bastbu opened this issue 3 years ago • 2 comments

Expected Behavior

Expensive log statements, such as logger.LogInformation($"cloud to device message: {((frmPayload?.Length ?? 0) == 0 ? "empty" : ConversionHelper.ByteArrayToString(frmPayload))}, id: {cloudToDeviceMessage.MessageId ?? "undefined"}, fport: {fport ?? 0}, confirmed: {requiresDeviceAcknowlegement}, cidType: {macCommandType}, macCommand: {macCommands.Count > 0}"); should only be executed if the log level is enabled.

Current Behavior

Many expensive log statement operations (string interpolations, conversions, etc) are always executed.

bastbu avatar Nov 17 '21 07:11 bastbu

@atifaziz looking if needed in .net 6

Mandur avatar Nov 17 '21 08:11 Mandur

Based on an initial look, it seems like that logging did not get any update with regards to optimised and optional string interpolation. Either we can add this support or go with a lightweight level-logging wrapper that short-circuits any work if the right logging level is not in effect. If we want to use structure logging instead, then there are other options still.

atifaziz avatar Nov 17 '21 14:11 atifaziz