Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine related log messages to ones. #4950

Merged
merged 1 commit into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -25,7 +26,7 @@ public class AbpExceptionFilter : IAsyncExceptionFilter, ITransientDependency

public AbpExceptionFilter(
IExceptionToErrorInfoConverter errorInfoConverter,
IHttpExceptionStatusCodeFinder statusCodeFinder,
IHttpExceptionStatusCodeFinder statusCodeFinder,
IJsonSerializer jsonSerializer)
{
_errorInfoConverter = errorInfoConverter;
Expand Down Expand Up @@ -54,7 +55,7 @@ protected virtual bool ShouldHandleException(ExceptionContext context)
{
return true;
}

if (context.HttpContext.Request.CanAccept(MimeTypes.Application.Json))
{
return true;
Expand All @@ -81,8 +82,11 @@ protected virtual async Task HandleAndWrapException(ExceptionContext context)

var logLevel = context.Exception.GetLogLevel();

Logger.LogWithLevel(logLevel, $"---------- {nameof(RemoteServiceErrorInfo)} ----------");
Logger.LogWithLevel(logLevel, _jsonSerializer.Serialize(remoteServiceErrorInfo, indented: true));
var remoteServiceErrorInfoBuilder = new StringBuilder();
remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------");
remoteServiceErrorInfoBuilder.AppendLine( _jsonSerializer.Serialize(remoteServiceErrorInfo, indented: true));
Logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString());

Logger.LogException(context.Exception, logLevel);

await context.HttpContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -93,8 +94,11 @@ protected virtual async Task HandleAndWrapException(PageHandlerExecutedContext c

var logLevel = context.Exception.GetLogLevel();

Logger.LogWithLevel(logLevel, $"---------- {nameof(RemoteServiceErrorInfo)} ----------");
Logger.LogWithLevel(logLevel, _jsonSerializer.Serialize(remoteServiceErrorInfo, indented: true));
var remoteServiceErrorInfoBuilder = new StringBuilder();
remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------");
remoteServiceErrorInfoBuilder.AppendLine( _jsonSerializer.Serialize(remoteServiceErrorInfo, indented: true));
Logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString());

Logger.LogException(context.Exception, logLevel);

await context.HttpContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Logging;

Expand Down Expand Up @@ -87,12 +88,14 @@ private static void LogData(ILogger logger, Exception exception, LogLevel logLev
return;
}

logger.LogWithLevel(logLevel, "---------- Exception Data ----------");

var exceptionData = new StringBuilder();
exceptionData.AppendLine("---------- Exception Data ----------");
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using Microsoft.Extensions.Logging;
using Volo.Abp.Logging;

Expand All @@ -12,9 +13,9 @@ namespace Volo.Abp.Validation
/// This exception type is used to throws validation exceptions.
/// </summary>
[Serializable]
public class AbpValidationException : AbpException,
IHasLogLevel,
IHasValidationErrors,
public class AbpValidationException : AbpException,
IHasLogLevel,
IHasValidationErrors,
IExceptionWithSelfLogging
{
/// <summary>
Expand Down Expand Up @@ -99,7 +100,8 @@ public void Log(ILogger logger)
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)
{
var memberNames = "";
Expand All @@ -108,8 +110,10 @@ public void Log(ILogger logger)
memberNames = " (" + string.Join(", ", validationResult.MemberNames) + ")";
}

logger.LogWithLevel(LogLevel, validationResult.ErrorMessage + memberNames);
validationErrors.AppendLine(validationResult.ErrorMessage + memberNames);
}

logger.LogWithLevel(LogLevel, validationErrors.ToString());
}
}
}