private NodePool CreateNodePool()

in src/Elastic.NLog.Targets/ElasticsearchTarget.cs [257:301]


		private NodePool CreateNodePool()
		{
			var nodeUris = NodeUris?.Render(LogEventInfo.CreateNullEvent()).Split(new[] { ',' }).Select(uri => uri.Trim()).Where(uri => !string.IsNullOrEmpty(uri)).Select(uri => new Uri(uri)).ToArray() ?? Array.Empty<Uri>();
			if (nodeUris.Length == 0 && NodePoolType != ElasticPoolType.Cloud)
				return new SingleNodePool(new Uri("http://localhost:9200"));
			if (NodePoolType == ElasticPoolType.SingleNode || NodePoolType == ElasticPoolType.Unknown && nodeUris.Length == 1)
				return new SingleNodePool(nodeUris[0]);

			switch (NodePoolType)
			{
				case ElasticPoolType.Unknown:
				case ElasticPoolType.Sniffing:
					return new SniffingNodePool(nodeUris);
				case ElasticPoolType.Static:
					return new StaticNodePool(nodeUris);
				case ElasticPoolType.Sticky:
					return new StickyNodePool(nodeUris);
				case ElasticPoolType.Cloud:
					var cloudId = CloudId?.Render(LogEventInfo.CreateNullEvent()) ?? string.Empty;
					if (string.IsNullOrEmpty(cloudId))
						throw new NLogConfigurationException($"ElasticSearch Cloud {nameof(CloudNodePool)} requires '{nameof(CloudId)}' to be provided as well");

					var apiKey = ApiKey?.Render(LogEventInfo.CreateNullEvent()) ?? string.Empty;
					if (!string.IsNullOrEmpty(apiKey))
					{
						var apiKeyCredentials = new ApiKey(apiKey);
						return new CloudNodePool(cloudId, apiKeyCredentials);
					}

					var username = Username?.Render(LogEventInfo.CreateNullEvent()) ?? string.Empty;
					var password = Password?.Render(LogEventInfo.CreateNullEvent()) ?? string.Empty;
					if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
					{
						var basicAuthCredentials = new BasicAuthentication(username, password);
						return new CloudNodePool(cloudId, basicAuthCredentials);
					}

					throw new NLogConfigurationException($"ElasticSearch Cloud requires either '{nameof(ApiKey)}' or"
						+ $"'{nameof(Username)}' and '{nameof(Password)}");
				//case ElasticPoolType.StickySniffing:
				default:
					throw new NLogConfigurationException($"Unrecognised ElasticSearch connection pool type '{NodePoolType}' specified in the configuration.",
						nameof(NodePoolType));
			}
		}