Show answerHide answer
Correct answer: C if(_logger.DebugEnabled) { _logger.debug(logPrefix + someReallyExpensiveOperation()) }
Explanation
Answer Option (Which option is correct) C. if(_logger.DebugEnabled) { _logger.debug(logPrefix + someReallyExpensiveOperation()) }Explanation:
Guard an expensive debug-message expression with the matching DebugEnabled check. That prevents the expensive operation from running when debug logging is disabled. Include useful diagnostic context and avoid excessive output or unmasked personal information.
Why the other options are incorrect:
A. if(_logger.InfoEnabled) { _logger.debug("Adding '${contact.PublicID}' to ContactManager") }:
The guard checks the info level. The actual call writes at debug level. Those levels can be enabled differently.
B. _logger.error(DisplayKey.get("Web.ContactManager.Error.GeneralException", e.Message)):
DisplayKey creates localized interface text. The proposal does not demonstrate stable diagnostic context or controlled exception handling. The guarded expensive debug call is the stronger listed choice.
D. _logger.info(logPrefix + "[Address#AddressLine1=" + address.AddressLine1 + "] [Address#City" + address.City + "] [Address#State" + address.State + "]"):
The log records a street address and location. Those values can identify a person. The message should avoid exposing clear-text address data.
References:
Apache Log4j - Disabled logging and expensive message construction
Guidewire Security - Logging sensitive information