ASP.NET Core Interview Question #174

How should sensitive information be handled in logs?

Logging, Error Handling & Background Services Mid-Level Intermediate

Quick Interview Answer

Sensitive information should not be logged unless there is a specific, justified, and protected requirement. Passwords, authentication tokens, secret keys, full connection strings, payment credentials, and other confidential values should never appear in ordinary application logs.

Detailed Explanation

Sensitive information should not be logged unless there is a specific, justified, and protected requirement. Passwords, authentication tokens, secret keys, full connection strings, payment credentials, and other confidential values should never appear in ordinary application logs.

Personal data should be minimized and handled according to the application's privacy and compliance requirements. Prefer stable internal identifiers over unnecessary personal details.

Log storage itself should have access controls, retention policies, secure transport, and monitoring because logs can become a valuable target if they contain operational or user information.

Code Example

// Good: useful identifier without secret data
_logger.LogInformation(
    "Password reset requested for UserId {UserId}",
    user.Id);

// Never log:
// password, reset token, access token, API secret, etc.