Refaktorisiere LogNotice, um ILogger ohne Generika zu verwenden, und füge eine Überladung hinzu, um Result-Objekte direkt zu loggen.

This commit is contained in:
Developer 02
2024-05-02 16:28:05 +02:00
parent 2521d3d887
commit 94da0733ce
2 changed files with 6 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.Infrastructure;
using DigitalData.Core.DTO;
using Microsoft.AspNetCore.Mvc;
namespace DigitalData.Core.API
@@ -57,6 +58,7 @@ namespace DigitalData.Core.API
var routeValues = new { id = createdResource.Id };
return CreatedAtAction(actionName, routeValues, createdResource);
}
return BadRequest(result);
}

View File

@@ -84,7 +84,7 @@ namespace DigitalData.Core.DTO
return result.IsSuccess ? Try(result.Data) : Catch(result.Messages, result.Notices);
}
public static void LogNotice<T>(this ILogger<T> logger, IEnumerable<Notice> notices, string start = ": ", string seperator = ". ", string end = ".\n")
public static void LogNotice(this ILogger logger, IEnumerable<Notice> notices, string start = ": ", string seperator = ". ", string end = ".\n")
{
foreach(LogLevel level in Enum.GetValues(typeof(LogLevel)))
{
@@ -106,5 +106,8 @@ namespace DigitalData.Core.DTO
logger.Log(level, sb.ToString());
}
}
public static void LogNotice(this ILogger logger, Result result, string start = ": ", string seperator = ". ", string end = ".\n")
=> logger.LogNotice(notices: result.Notices, start: start, seperator: seperator, end: end);
}
}