Browse Source

Merge pull request #4950 from abpframework/maliming/log-patch

Combine related log messages to ones.
pull/5011/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
6876bfb3af
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs
  2. 8
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs
  3. 9
      framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs
  4. 14
      framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/AbpValidationException.cs

12
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -25,7 +26,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
public AbpExceptionFilter( public AbpExceptionFilter(
IExceptionToErrorInfoConverter errorInfoConverter, IExceptionToErrorInfoConverter errorInfoConverter,
IHttpExceptionStatusCodeFinder statusCodeFinder, IHttpExceptionStatusCodeFinder statusCodeFinder,
IJsonSerializer jsonSerializer) IJsonSerializer jsonSerializer)
{ {
_errorInfoConverter = errorInfoConverter; _errorInfoConverter = errorInfoConverter;
@ -54,7 +55,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
{ {
return true; return true;
} }
if (context.HttpContext.Request.CanAccept(MimeTypes.Application.Json)) if (context.HttpContext.Request.CanAccept(MimeTypes.Application.Json))
{ {
return true; return true;
@ -81,8 +82,11 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
var logLevel = context.Exception.GetLogLevel(); var logLevel = context.Exception.GetLogLevel();
Logger.LogWithLevel(logLevel, $"---------- {nameof(RemoteServiceErrorInfo)} ----------"); var remoteServiceErrorInfoBuilder = new StringBuilder();
Logger.LogWithLevel(logLevel, _jsonSerializer.Serialize(remoteServiceErrorInfo, indented: true)); remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------");
remoteServiceErrorInfoBuilder.AppendLine( _jsonSerializer.Serialize(remoteServiceErrorInfo, indented: true));
Logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString());
Logger.LogException(context.Exception, logLevel); Logger.LogException(context.Exception, logLevel);
await context.HttpContext await context.HttpContext

8
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -93,8 +94,11 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
var logLevel = context.Exception.GetLogLevel(); var logLevel = context.Exception.GetLogLevel();
Logger.LogWithLevel(logLevel, $"---------- {nameof(RemoteServiceErrorInfo)} ----------"); var remoteServiceErrorInfoBuilder = new StringBuilder();
Logger.LogWithLevel(logLevel, _jsonSerializer.Serialize(remoteServiceErrorInfo, indented: true)); remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------");
remoteServiceErrorInfoBuilder.AppendLine( _jsonSerializer.Serialize(remoteServiceErrorInfo, indented: true));
Logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString());
Logger.LogException(context.Exception, logLevel); Logger.LogException(context.Exception, logLevel);
await context.HttpContext await context.HttpContext

9
framework/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using Volo.Abp.ExceptionHandling; using Volo.Abp.ExceptionHandling;
using Volo.Abp.Logging; using Volo.Abp.Logging;
@ -87,12 +88,14 @@ namespace Microsoft.Extensions.Logging
return; return;
} }
logger.LogWithLevel(logLevel, "---------- Exception Data ----------"); var exceptionData = new StringBuilder();
exceptionData.AppendLine("---------- Exception Data ----------");
foreach (var key in exception.Data.Keys) foreach (var key in exception.Data.Keys)
{ {
logger.LogWithLevel(logLevel, $"{key} = {exception.Data[key]}"); exceptionData.AppendLine($"{key} = {exception.Data[key]}");
} }
logger.LogWithLevel(logLevel, exceptionData.ToString());
} }
private static void LogSelfLogging(ILogger logger, Exception exception) private static void LogSelfLogging(ILogger logger, Exception exception)

14
framework/src/Volo.Abp.Validation.Abstractions/Volo/Abp/Validation/AbpValidationException.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Volo.Abp.Logging; using Volo.Abp.Logging;
@ -12,9 +13,9 @@ namespace Volo.Abp.Validation
/// This exception type is used to throws validation exceptions. /// This exception type is used to throws validation exceptions.
/// </summary> /// </summary>
[Serializable] [Serializable]
public class AbpValidationException : AbpException, public class AbpValidationException : AbpException,
IHasLogLevel, IHasLogLevel,
IHasValidationErrors, IHasValidationErrors,
IExceptionWithSelfLogging IExceptionWithSelfLogging
{ {
/// <summary> /// <summary>
@ -99,7 +100,8 @@ namespace Volo.Abp.Validation
return; return;
} }
logger.LogWithLevel(LogLevel, "There are " + ValidationErrors.Count + " validation errors:"); var validationErrors = new StringBuilder();
validationErrors.AppendLine("There are " + ValidationErrors.Count + " validation errors:");
foreach (var validationResult in ValidationErrors) foreach (var validationResult in ValidationErrors)
{ {
var memberNames = ""; var memberNames = "";
@ -108,8 +110,10 @@ namespace Volo.Abp.Validation
memberNames = " (" + string.Join(", ", validationResult.MemberNames) + ")"; memberNames = " (" + string.Join(", ", validationResult.MemberNames) + ")";
} }
logger.LogWithLevel(LogLevel, validationResult.ErrorMessage + memberNames); validationErrors.AppendLine(validationResult.ErrorMessage + memberNames);
} }
logger.LogWithLevel(LogLevel, validationErrors.ToString());
} }
} }
} }

Loading…
Cancel
Save