/// <summary> /// <inheritdoc cref="ObjectValueFormatter.Format(TextWriter,object,string,IFormatProvider)"/> /// </summary> public static void Format( [NotNull] TextWriter writer, [CanBeNull] object value, [CanBeNull] string format = null, [CanBeNull] IFormatProvider formatProvider = null) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (value == null) { return; } if (PaddingFormatHelper.TryParseFormat(format, out var insertLeadingSpace, out var insertTrailingSpace)) { format = null; } if (insertLeadingSpace) { writer.WriteSpace(); } ObjectValueFormatter.Format(writer, value, format, formatProvider); if (insertTrailingSpace) { writer.WriteSpace(); } }
private static void BuildAnnotationsContainer(IHerculesTagsBuilder builder, ISpan span, IFormatProvider formatProvider) { foreach (var pair in span.Annotations) { if (builder.TryAddObject(pair.Key, pair.Value)) { continue; } builder.AddValue(pair.Key, ObjectValueFormatter.Format(pair.Value, formatProvider: formatProvider)); } }
public static IHerculesTagsBuilder AddProperties( this IHerculesTagsBuilder builder, LogEvent @event, IReadOnlyCollection <string> filteredProperties, IFormatProvider formatProvider) { foreach (var keyValuePair in @event.Properties !) { var key = keyValuePair.Key; if (IsPositionalName(key)) { continue; } if (filteredProperties?.Contains(key) == true) { continue; } var value = keyValuePair.Value; if (key == WellKnownProperties.OperationContext && value is OperationContextValue operationContextValue) { value = operationContextValue.Select(t => OperationContextValueFormatter.Format(@event, t, null, formatProvider)).ToArray(); } if (builder.TryAddObject(key, value)) { continue; } var format = value is DateTime || value is DateTimeOffset ? "O" : null; builder.AddValue(key, ObjectValueFormatter.Format(value, format)); } return(builder); }