From 06e2aed9ecb97d28b23ec8e544f986ba69b4196f Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Sat, 1 Feb 2025 10:01:26 +0100 Subject: [PATCH] Marked JsonLayout EscapeForwardSlash as obsolete --- src/NLog/Layouts/JSON/JsonAttribute.cs | 8 +++++++- src/NLog/Layouts/JSON/JsonLayout.cs | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/NLog/Layouts/JSON/JsonAttribute.cs b/src/NLog/Layouts/JSON/JsonAttribute.cs index 86f39ac453..23e1fe8bd4 100644 --- a/src/NLog/Layouts/JSON/JsonAttribute.cs +++ b/src/NLog/Layouts/JSON/JsonAttribute.cs @@ -34,6 +34,7 @@ namespace NLog.Layouts { using System; + using System.ComponentModel; using System.Text; using NLog.Config; @@ -133,6 +134,8 @@ public string Name /// If not set explicitly then the value of the parent will be used as default. /// /// + [Obsolete("Marked obsolete since forward slash are valid JSON. Marked obsolete with NLog v5.4")] + [EditorBrowsable(EditorBrowsableState.Never)] public bool EscapeForwardSlash { get => EscapeForwardSlashInternal ?? false; set => EscapeForwardSlashInternal = value; } internal bool? EscapeForwardSlashInternal { get; private set; } @@ -170,7 +173,10 @@ internal bool RenderAppendJsonValue(LogEventInfo logEvent, IJsonConverter jsonCo if (Encode) { - Targets.DefaultJsonSerializer.PerformJsonEscapeWhenNeeded(builder, orgLength, EscapeUnicode, EscapeForwardSlash); +#pragma warning disable CS0618 // Type or member is obsolete + var escapeForwardSlash = EscapeForwardSlash; +#pragma warning restore CS0618 // Type or member is obsolete + Targets.DefaultJsonSerializer.PerformJsonEscapeWhenNeeded(builder, orgLength, EscapeUnicode, escapeForwardSlash); builder.Append('"'); } } diff --git a/src/NLog/Layouts/JSON/JsonLayout.cs b/src/NLog/Layouts/JSON/JsonLayout.cs index fe27503525..a38498fc8b 100644 --- a/src/NLog/Layouts/JSON/JsonLayout.cs +++ b/src/NLog/Layouts/JSON/JsonLayout.cs @@ -261,7 +261,9 @@ protected override void InitializeLayout() { if (!attribute.EscapeForwardSlashInternal.HasValue) { +#pragma warning disable CS0618 // Type or member is obsolete attribute.EscapeForwardSlash = _escapeForwardSlashInternal.Value; +#pragma warning restore CS0618 // Type or member is obsolete } } }