Browse Source

Improve logging of exceptions by ensuring error codes and details are not null or whitespace

pull/22339/head
maliming 11 months ago
parent
commit
f7a36f6055
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 4
      framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs

4
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);
}

Loading…
Cancel
Save