From f0e8e9519c6d524a21d76c570b215f3a5946217f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 1 May 2018 10:00:22 +0300 Subject: [PATCH] Log exception's error code and details too. --- .../Extensions/Logging/AbpLoggerExtensions.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs b/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs index 2011480332..bea0caeaff 100644 --- a/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs +++ b/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Volo.Abp.ExceptionHandling; using Volo.Abp.Logging; namespace Microsoft.Extensions.Logging @@ -61,10 +62,24 @@ namespace Microsoft.Extensions.Logging var selectedLevel = level ?? ex.GetLogLevel(); logger.LogWithLevel(selectedLevel, ex.Message, ex); - LogDetails(logger, ex); + LogKnownProperties(logger, ex, selectedLevel); + LogSelfLogging(logger, ex); LogData(logger, ex, selectedLevel); } + private static void LogKnownProperties(ILogger logger, Exception exception, LogLevel logLevel) + { + if (exception is IHasErrorCode exceptionWithErrorCode) + { + logger.LogWithLevel(logLevel, "Code:" + exceptionWithErrorCode.Code); + } + + if (exception is IHasErrorDetails exceptionWithErrorDetails) + { + logger.LogWithLevel(logLevel, "Details:" + exceptionWithErrorDetails.Details); + } + } + private static void LogData(ILogger logger, Exception exception, LogLevel logLevel) { if (exception.Data == null || exception.Data.Count <= 0) @@ -80,7 +95,7 @@ namespace Microsoft.Extensions.Logging } } - private static void LogDetails(ILogger logger, Exception exception) + private static void LogSelfLogging(ILogger logger, Exception exception) { var loggingExceptions = new List();