/// <summary> /// Build a connection to the shield queues service bus for the current protection process. /// </summary> /// <param name="externalConnection"></param> /// <param name="withLogger"></param> /// <returns></returns> private QueueConnection InstanceQueueConnector(QueueConnectionExternalModel externalConnection, bool withLogger) { try { var connection = new QueueConnection(externalConnection.TaskId); if (!withLogger) { return(connection); } if (Parent.CustomLogger is null) { throw new Exception("The \"WithLogger\" method cannot be called if a custom logger has not been provided in the shield client."); } Parent.CustomLogger?.LogDebug("The current logger has been configured as the output of the connection logs."); connection.On(externalConnection.OnLogger, (message, level, time) => OnCustomLog(time.ToString(CultureInfo.InvariantCulture), message, level)); return(connection); } catch (Exception ex) { Parent.CustomLogger?.LogCritical("An error occurred while creating the connection to the shield server for the current process."); throw new Exception($"An error occurred while creating the connection to the shield server for the current process: {ex.Message}"); } }