using EnvelopeGenerator.Application.Services; using Microsoft.Extensions.Logging; using System.Text; namespace EnvelopeGenerator.Application { public static class EnvelopeGeneratorExtensions { public static void LogEnvelopeError(this ILogger logger, string envelopeEeceiverId, Exception? exception = null, string? message = null, params object?[] args) { var sb = new StringBuilder(envelopeEeceiverId.DecodeEnvelopeReceiverId().ToTitle()); if (message is not null) sb.AppendLine().Append(message); if(exception is null) logger.Log(LogLevel.Error, sb.ToString(), args); else logger.Log(LogLevel.Error, exception, sb.ToString(), args); } public static void LogEnvelopeError(this ILogger logger, string? uuid, string? signature = null, Exception? exception = null, string? message = null, params object?[] args) { var sb = new StringBuilder($"Envelope Uuid: {uuid}"); if(signature is not null) sb.AppendLine().Append($"Receiver Signature: {signature}"); if (message is not null) sb.AppendLine().Append(message); if (exception is null) logger.Log(LogLevel.Error, sb.ToString(), args); else logger.Log(LogLevel.Error, exception, sb.ToString(), args); } public static string ToTitle(this (string? UUID, string? Signature) envelopeReceiverTuple) { return $"UUID is {envelopeReceiverTuple.UUID} and \n signature is {envelopeReceiverTuple.Signature}"; } } }