public static StatisticsResult send(@NotNull EventLogSendConfig config,
                                      @NotNull EventLogSettingsService settings,
                                      @NotNull EventLogResultDecorator decorator) {
    final EventLogApplicationInfo info = settings.getApplicationInfo();
    final DataCollectorDebugLogger logger = info.getLogger();

    final List<EventLogFile> logs = getLogFiles(config, logger);
    if (!config.isSendEnabled()) {
      cleanupEventLogFiles(logs, logger);
      return new StatisticsResult(ResultCode.NOTHING_TO_SEND, "Event Log collector is not enabled");
    }

    if (logs.isEmpty()) {
      return new StatisticsResult(ResultCode.NOTHING_TO_SEND, "No files to send");
    }

    if (!settings.isSettingsReachable()) {
      return new StatisticsResult(StatisticsResult.ResultCode.ERROR_IN_CONFIG, "ERROR: settings server is unreachable");
    }

    if (!settings.isSendEnabled()) {
      cleanupEventLogFiles(logs, logger);
      return new StatisticsResult(StatisticsResult.ResultCode.NOT_PERMITTED_SERVER, "NOT_PERMITTED");
    }

    final String serviceUrl = settings.getServiceUrl();
    if (serviceUrl == null) {
      return new StatisticsResult(StatisticsResult.ResultCode.ERROR_IN_CONFIG, "ERROR: unknown Statistics Service URL.");
    }

    final boolean isInternal = info.isInternal();
    final String productCode = info.getProductCode();
    EventLogBuildType defaultBuildType = getDefaultBuildType(info.isEAP());
    LogEventFilter baseFilter = settings.getBaseEventFilter();

    MachineId machineId = getActualOrDisabledMachineId(config.getMachineId(), settings);
    try {
      EventLogConnectionSettings connectionSettings = info.getConnectionSettings();

      decorator.onLogsLoaded(logs.size());
      final List<File> toRemove = new ArrayList<>(logs.size());
      for (EventLogFile logFile : logs) {
        File file = logFile.getFile();
        EventLogBuildType type = logFile.getType(defaultBuildType);
        LogEventFilter filter = settings.getEventFilter(baseFilter, type);
        String deviceId = config.getDeviceId();
        LogEventRecordRequest recordRequest =
          LogEventRecordRequest.Companion.create(file, config.getRecorderId(), productCode, deviceId, filter, isInternal, logger,
                                                 machineId, config.isEscapingEnabled());
        ValidationErrorInfo error = validate(recordRequest, file);
        if (error != null) {
          if (logger.isTraceEnabled()) {
            logger.trace(file.getName() + "-> " + error.getMessage());
          }
          decorator.onFailed(recordRequest, error.getCode(), null);
          toRemove.add(file);
          continue;
        }

        try {
          StatsHttpRequests.post(serviceUrl, connectionSettings).
            withBody(LogEventSerializer.INSTANCE.toString(recordRequest), "application/json", StandardCharsets.UTF_8).
            succeed((r, code) -> {
              toRemove.add(file);
              decorator.onSucceed(recordRequest, loadAndLogResponse(logger, r, file), file.getAbsolutePath());
            }).
            fail((r, code) -> {
              if (code == HttpURLConnection.HTTP_BAD_REQUEST) {
                toRemove.add(file);
              }
              decorator.onFailed(recordRequest, code, loadAndLogResponse(logger, r, file));
            }).send();
        }
        catch (Exception e) {
          if (logger.isTraceEnabled()) {
            logger.trace(file.getName() + " -> " + e.getMessage());
          }
          //noinspection InstanceofCatchParameter
          int errorCode = e instanceof StatsRequestBuilder.InvalidHttpRequest ? ((StatsRequestBuilder.InvalidHttpRequest)e).getCode() : 50;
          decorator.onFailed(null, errorCode, null);
        }
      }

      cleanupFiles(toRemove, logger);
      return decorator.onFinished();
    }
    catch (Exception e) {
      final String message = e.getMessage();
      logger.info(message != null ? message : "", e);
      throw new StatServiceException("Error during data sending.", e);
    }
  }
public static StatisticsResult send(@NotNull EventLogSendConfig config,
                                      @NotNull EventLogSettingsService settings,
                                      @NotNull EventLogResultDecorator decorator)