From bf2c2ab392844b4fb820546fe659fdb3df7c609a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Thu, 29 Jun 2023 08:11:40 +0200 Subject: [PATCH] Deprecate Log4jTextFormatter and Log4netTextFormatter Recommend using [Serilog.Formatting.Log4Net](https://github.com/serilog-contrib/serilog-formatting-log4net) instead. --- README.md | 30 +------------------ .../Udp/TextFormatters/Log4jTextFormatter.cs | 2 ++ .../TextFormatters/Log4netTextFormatter.cs | 2 ++ .../Log4jTextFormatterShould.cs | 1 + .../Log4netTextFormatterShould.cs | 1 + 5 files changed, 7 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 78cf484..1c340ae 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ __Package__ - [Serilog.Sinks.Udp](https://www.nuget.org/packages/serilog.sinks.u - [Super simple to use](#super-simple-to-use) - [Typical use case](#typical-use-case) - [Event formatters](#event-formatters) - - [`Log4jTextFormatter`](#log4jtextformatter) - - [`Log4netTextFormatter`](#log4nettextformatter) - [Sample applications](#sample-applications) - [Install via NuGet](#install-via-nuget) - [Donations](#donations) @@ -86,33 +84,7 @@ Taking it to the next level is when you as a team agree on sending the log event The event formatter is an output template on steroids. It has the responsibility of turning a single log event into a textual representation. It can serialize the log event into JSON, XML or anything else that matches the expectations of the receiver. -The sink comes pre-loaded with two XML based event formatters. One is matching the log4j schema expected by Log2Console and the other is matching the log4net schema expected by [Log4View](http://www.log4view.com). - -### `Log4jTextFormatter` - -The log event is formatted according to the log4j XML schema expected by Log2Console. - -```xml - - Something failed - An exception describing the failure - -``` - -### `Log4netTextFormatter` - -The log event is formatted according to the log4net XML schema expected by Log4View. - -```xml - - - - - - Something went wrong. - System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. - -``` +It is recommended to use the [Serilog.Formatting.Log4Net](https://github.com/serilog-contrib/serilog-formatting-log4net) NuGet package to format logs as log4net or log4j format. You can then use [Log4View](http://www.log4view.com) or [Log2Console](https://github.com/Statyk7/log2console) for example to look at the logs while they are transmitted over UDP. ## Sample applications diff --git a/src/Serilog.Sinks.Udp/Sinks/Udp/TextFormatters/Log4jTextFormatter.cs b/src/Serilog.Sinks.Udp/Sinks/Udp/TextFormatters/Log4jTextFormatter.cs index 9fa1adc..7e78638 100644 --- a/src/Serilog.Sinks.Udp/Sinks/Udp/TextFormatters/Log4jTextFormatter.cs +++ b/src/Serilog.Sinks.Udp/Sinks/Udp/TextFormatters/Log4jTextFormatter.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using Serilog.Events; using Serilog.Formatting; using System.IO; @@ -23,6 +24,7 @@ namespace Serilog.Sinks.Udp.TextFormatters; /// /// Text formatter serializing log events into log4j compliant XML. /// +[Obsolete("Consider using the Log4NetTextFormatter class from the Serilog.Formatting.Log4Net package instead, see https://github.com/serilog-contrib/serilog-formatting-log4net")] public class Log4jTextFormatter : ITextFormatter { private static readonly string SourceContextPropertyName = "SourceContext"; diff --git a/src/Serilog.Sinks.Udp/Sinks/Udp/TextFormatters/Log4netTextFormatter.cs b/src/Serilog.Sinks.Udp/Sinks/Udp/TextFormatters/Log4netTextFormatter.cs index a9e3f81..f5ecfe6 100644 --- a/src/Serilog.Sinks.Udp/Sinks/Udp/TextFormatters/Log4netTextFormatter.cs +++ b/src/Serilog.Sinks.Udp/Sinks/Udp/TextFormatters/Log4netTextFormatter.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using Serilog.Events; using Serilog.Formatting; using System.IO; @@ -22,6 +23,7 @@ namespace Serilog.Sinks.Udp.TextFormatters; /// /// Text formatter serializing log events into log4net compliant XML. /// +[Obsolete("Consider using the Log4NetTextFormatter class from the Serilog.Formatting.Log4Net package instead, see https://github.com/serilog-contrib/serilog-formatting-log4net")] public class Log4netTextFormatter : ITextFormatter { private static readonly string SourceContextPropertyName = "SourceContext"; diff --git a/test/Serilog.Sinks.Udp.Tests/Sinks/Udp/TextFormatters/Log4jTextFormatterShould.cs b/test/Serilog.Sinks.Udp.Tests/Sinks/Udp/TextFormatters/Log4jTextFormatterShould.cs index 5f25ceb..2c5795c 100644 --- a/test/Serilog.Sinks.Udp.Tests/Sinks/Udp/TextFormatters/Log4jTextFormatterShould.cs +++ b/test/Serilog.Sinks.Udp.Tests/Sinks/Udp/TextFormatters/Log4jTextFormatterShould.cs @@ -8,6 +8,7 @@ namespace Serilog.Sinks.Udp.TextFormatters; +[Obsolete("Can be deleted once the Log4jTextFormatter class is removed")] public class Log4jTextFormatterShould { private static readonly XNamespace Namespace = "http://jakarta.apache.org/log4j/"; diff --git a/test/Serilog.Sinks.Udp.Tests/Sinks/Udp/TextFormatters/Log4netTextFormatterShould.cs b/test/Serilog.Sinks.Udp.Tests/Sinks/Udp/TextFormatters/Log4netTextFormatterShould.cs index b7da6cc..83a58f9 100644 --- a/test/Serilog.Sinks.Udp.Tests/Sinks/Udp/TextFormatters/Log4netTextFormatterShould.cs +++ b/test/Serilog.Sinks.Udp.Tests/Sinks/Udp/TextFormatters/Log4netTextFormatterShould.cs @@ -8,6 +8,7 @@ namespace Serilog.Sinks.Udp.TextFormatters; +[Obsolete("Can be deleted once the Log4jTextFormatter class is removed")] public class Log4netTextFormatterShould { private static readonly XNamespace Namespace = "http://logging.apache.org/log4net/schemas/log4net-events-1.2/";