private static MetadataDictionary GetMetadata()

in src/Elastic.CommonSchema.Log4net/LoggingEventConverter.cs [61:105]


	private static MetadataDictionary GetMetadata(LoggingEvent loggingEvent)
	{
		var properties = loggingEvent.GetProperties();
		if (properties.Count == 0)
			return null;

		var metadata = new MetadataDictionary();

		foreach (var property in properties.GetKeys())
		{
			switch (property)
			{
				case LoggingEvent.HostNameProperty:
				case LoggingEvent.IdentityProperty:
				case LoggingEvent.UserNameProperty:
					continue;
			}

			var value = properties[property];

			// use latest string representation of the value in the stack
			if (value is ThreadContextStack tcs)
			{
				var stackValue = tcs.Peek();
				value = !string.IsNullOrEmpty(stackValue) ? stackValue : null;
			}
			else if (value is LogicalThreadContextStack ltcs)
			{
				var stackValue = ltcs.Peek();
				value = !string.IsNullOrEmpty(stackValue) ? stackValue : null;
			}

			if (value != null)
				metadata[property] = value;
		}

		if (loggingEvent.MessageObject is SystemStringFormat format)
		{
			metadata["MessageTemplate"] = format.Format;
			for (var i = 0; i < format.Args.Length; i++)
				metadata[i.ToString()] = format.Args[0];
		}

		return metadata.Count > 0 ? metadata : null;
	}