From f7a36f60551c776bd5d8ce1d6b49ed89ff4da0fa Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 12 Mar 2025 09:34:52 +0800 Subject: [PATCH] Improve logging of exceptions by ensuring error codes and details are not null or whitespace --- .../Microsoft/Extensions/Logging/AbpLoggerExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs b/framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs index 18a93f7348..e1899f7efc 100644 --- a/framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs +++ b/framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs @@ -70,12 +70,12 @@ public static class AbpLoggerExtensions private static void LogKnownProperties(ILogger logger, Exception exception, LogLevel logLevel) { - if (exception is IHasErrorCode exceptionWithErrorCode) + if (exception is IHasErrorCode exceptionWithErrorCode && !exceptionWithErrorCode.Code.IsNullOrWhiteSpace()) { logger.LogWithLevel(logLevel, "Code:" + exceptionWithErrorCode.Code); } - if (exception is IHasErrorDetails exceptionWithErrorDetails) + if (exception is IHasErrorDetails exceptionWithErrorDetails && !exceptionWithErrorDetails.Details.IsNullOrWhiteSpace()) { logger.LogWithLevel(logLevel, "Details:" + exceptionWithErrorDetails.Details); }