Esempio n. 1
0
        /// <inheritdoc />
        public void WriteTo(Utf8JsonWriter writer)
        {
            writer.WriteStartObject();

            // Message
            if (!string.IsNullOrWhiteSpace(Message))
            {
                writer.WriteString("message", Message);
            }

            // Params
            if (Params is {} @params)
            {
                writer.WriteStartArray("params");

                foreach (var i in @params)
                {
                    writer.WriteDynamicValue(i);
                }

                writer.WriteEndArray();
            }

            // Formatted
            if (!string.IsNullOrWhiteSpace(Formatted))
            {
                writer.WriteString("formatted", Formatted);
            }

            writer.WriteEndObject();
        }
 public static void WriteDynamic(
     this Utf8JsonWriter writer,
     string propertyName,
     object?value)
 {
     writer.WritePropertyName(propertyName);
     writer.WriteDynamicValue(value);
 }
Esempio n. 3
0
 public string ToJsonString(object @object)
 {
     using var stream = new MemoryStream();
     using (var writer = new Utf8JsonWriter(stream))
     {
         writer.WriteDynamicValue(@object);
     }
     return(Encoding.UTF8.GetString(stream.ToArray()));
 }
Esempio n. 4
0
 public static string ToJsonString(object @object)
 {
     using var stream = new MemoryStream();
     using (var writer = new Utf8JsonWriter(stream))
     {
         writer.WriteDynamicValue(@object, new TraceDiagnosticLogger(SentryLevel.Debug));
     }
     return(Encoding.UTF8.GetString(stream.ToArray()));
 }