private Service GetService()

in src/Elastic.CommonSchema.NLog/EcsLayout.cs [633:660]


		private Service GetService(LogEventInfo logEventInfo, Service defaultService)
		{
			var serviceName = ApmServiceName?.Render(logEventInfo);
			if (string.IsNullOrEmpty(serviceName))
				return defaultService;

			var serviceNodeName = ApmServiceNodeName?.Render(logEventInfo);
			var serviceVersion = ApmServiceVersion?.Render(logEventInfo);
			var serviceEnvironment = ServiceEnvironment?.Render(logEventInfo);

			var previousService = _previousService ?? defaultService;
			if ( (string.IsNullOrEmpty(serviceName) || serviceName == previousService?.Name)
			  && (string.IsNullOrEmpty(serviceNodeName) || serviceNodeName == previousService?.NodeName)
			  && (string.IsNullOrEmpty(serviceVersion) || serviceVersion == previousService?.Version)
			  && (string.IsNullOrEmpty(serviceEnvironment) || serviceEnvironment == previousService?.Environment))
				return previousService;

			var service = new Service
			{
				Name = string.IsNullOrEmpty(serviceName) ? previousService?.Name : serviceName,
				NodeName = string.IsNullOrEmpty(serviceNodeName) ? previousService?.NodeName : serviceNodeName,
				Version = string.IsNullOrEmpty(serviceVersion) ? previousService?.Version : serviceVersion,
				Environment = string.IsNullOrEmpty(serviceEnvironment) ? previousService?.Environment : serviceEnvironment,
				Type = previousService?.Type,
			};
			_previousService = service;
			return service;
		}