|
|
|
|
@ -1,8 +1,6 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Volo.Abp.Logging;
|
|
|
|
|
using Volo.Abp.Validation;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Extensions.Logging
|
|
|
|
|
{
|
|
|
|
|
@ -63,42 +61,37 @@ namespace Microsoft.Extensions.Logging
|
|
|
|
|
var logLevel = (ex as IHasLogLevel)?.LogLevel ?? LogLevel.Error;
|
|
|
|
|
|
|
|
|
|
logger.LogWithLevel(logLevel, ex.Message, ex);
|
|
|
|
|
LogValidationErrors(logger, ex);
|
|
|
|
|
LogDetails(logger, ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void LogValidationErrors(ILogger logger, Exception exception)
|
|
|
|
|
private static void LogDetails(ILogger logger, Exception exception)
|
|
|
|
|
{
|
|
|
|
|
//Try to find inner validation exception
|
|
|
|
|
if (exception is AggregateException && exception.InnerException != null)
|
|
|
|
|
{
|
|
|
|
|
var aggException = exception as AggregateException;
|
|
|
|
|
if (aggException.InnerException is AbpValidationException)
|
|
|
|
|
{
|
|
|
|
|
exception = aggException.InnerException;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var loggingExceptions = new List<IExceptionCanLogDetails>();
|
|
|
|
|
|
|
|
|
|
if (!(exception is AbpValidationException))
|
|
|
|
|
if (exception is IExceptionCanLogDetails)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
loggingExceptions.Add(exception as IExceptionCanLogDetails);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var validationException = exception as AbpValidationException;
|
|
|
|
|
if (validationException.ValidationErrors.IsNullOrEmpty())
|
|
|
|
|
else if (exception is AggregateException && exception.InnerException != null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var aggException = exception as AggregateException;
|
|
|
|
|
if (aggException.InnerException is IExceptionCanLogDetails)
|
|
|
|
|
{
|
|
|
|
|
loggingExceptions.Add(aggException.InnerException as IExceptionCanLogDetails);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.LogWithLevel(validationException.LogLevel, "There are " + validationException.ValidationErrors.Count + " validation errors:");
|
|
|
|
|
foreach (var validationResult in validationException.ValidationErrors)
|
|
|
|
|
{
|
|
|
|
|
var memberNames = "";
|
|
|
|
|
if (validationResult.MemberNames != null && validationResult.MemberNames.Any())
|
|
|
|
|
foreach (var innerException in aggException.InnerExceptions)
|
|
|
|
|
{
|
|
|
|
|
memberNames = " (" + string.Join(", ", validationResult.MemberNames) + ")";
|
|
|
|
|
if (innerException is IExceptionCanLogDetails)
|
|
|
|
|
{
|
|
|
|
|
loggingExceptions.AddIfNotContains(innerException as IExceptionCanLogDetails);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.LogWithLevel(validationException.LogLevel, validationResult.ErrorMessage + memberNames);
|
|
|
|
|
foreach (var ex in loggingExceptions)
|
|
|
|
|
{
|
|
|
|
|
ex.LogDetails(logger);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|