/// <inheritdoc /> public void WriteTo(Utf8JsonWriter writer) { writer.WriteStartObject(); // Data if (InternalData is {} data&& data.Any()) { writer.WriteStartObject("data"); foreach (var(key, value) in data) { writer.WriteDynamic(key, value); } writer.WriteEndObject(); } // Meta if (InternalMeta is {} meta&& meta.Any()) { writer.WriteStartObject("meta"); foreach (var(key, value) in meta) { writer.WriteDynamic(key, value); } writer.WriteEndObject(); } // Type if (!string.IsNullOrWhiteSpace(Type)) { writer.WriteString("type", Type); } // Description if (!string.IsNullOrWhiteSpace(Description)) { writer.WriteString("description", Description); } // Help link if (!string.IsNullOrWhiteSpace(HelpLink)) { writer.WriteString("help_link", HelpLink); } // Handled if (Handled is {} handled) { writer.WriteBoolean("handled", handled); } writer.WriteEndObject(); }
public void WriteDynamic_NonSerializableValue_LogException() { //Assert var logger = Substitute.For <IDiagnosticLogger>(); logger.IsEnabled(Arg.Any <SentryLevel>()).Returns(true); using var stream = new MemoryStream(); using (var writer = new Utf8JsonWriter(stream)) { writer.WriteStartObject(); // Act writer.WriteDynamic("property_name", new NonSerializableValue(), logger); writer.WriteEndObject(); } // Assert logger.Received(1).Log(Arg.Is(SentryLevel.Error), "Failed to serialize object for property '{0}'. Original depth: {1}, current depth: {2}", #if NETCOREAPP2_1 Arg.Is <TargetInvocationException>(e => e.InnerException.GetType() == typeof(InvalidDataException)), #else Arg.Any <InvalidDataException>(), #endif Arg.Any <object[]>()); }
/// <inheritdoc /> public void WriteTo(Utf8JsonWriter writer) { writer.WriteStartObject(); // Env if (InternalEnv is {} env&& env.Any()) { writer.WriteDictionary("env", env !); } // Other if (InternalOther is {} other&& other.Any()) { writer.WriteDictionary("other", other !); } // Headers if (InternalHeaders is {} headers&& headers.Any()) { writer.WriteDictionary("headers", headers !); } // Url if (!string.IsNullOrWhiteSpace(Url)) { writer.WriteString("url", Url); } // Method if (!string.IsNullOrWhiteSpace(Method)) { writer.WriteString("method", Method); } // Data if (Data is {} data) { writer.WriteDynamic("data", data); } // Query if (!string.IsNullOrWhiteSpace(QueryString)) { writer.WriteString("query_string", QueryString); } // Cookies if (!string.IsNullOrWhiteSpace(Cookies)) { writer.WriteString("cookies", Cookies); } writer.WriteEndObject(); }
public static void WriteDictionaryValue( this Utf8JsonWriter writer, IEnumerable <KeyValuePair <string, object?> >?dic) { if (dic != null) { writer.WriteStartObject(); foreach (var(key, value) in dic) { writer.WriteDynamic(key, value); } writer.WriteEndObject(); } else { writer.WriteNullValue(); } }