private static string FormatValue()

in src/Elastic.Extensions.Logging.Common/LogEventBuilderExtensions.cs [110:144]


	private static string FormatValue(object value, ILogEventCreationOptions options, int depth = 0, string? defaultFallback = null)
	{
		switch (value)
		{
			case null:
				return string.Empty;
			case byte b:
				return b.ToString("X2");
			case byte[] bytes:
				var builder = new StringBuilder("0x");
				foreach (var b in bytes) builder.Append(b.ToString("X2"));

				return builder.ToString();
			case DateTime dateTime:
				if (dateTime.TimeOfDay.Equals(TimeSpan.Zero))
					return dateTime.ToString("yyyy'-'MM'-'dd");

				return dateTime.ToString("o");
			case DateTimeOffset dateTimeOffset:
				return dateTimeOffset.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.ffffffzzz");
			case string s:
				// since 'string' implements IEnumerable, special case it
				return s;
			default:
				// need to special case dictionary before IEnumerable
				if (depth < 1 && value is IDictionary<string, object> dictionary)
					return FormatStringDictionary(dictionary, depth, options);

				// if the value implements IEnumerable, build a comma separated string
				if (depth < 1 && value is IEnumerable enumerable)
					return FormatEnumerable(enumerable, depth, options);

				return defaultFallback ?? value.ToString() ?? string.Empty;
		}
	}