diff --git a/CHANGELOG.md b/CHANGELOG.md index 75188bb..19288cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased][Unreleased] + +- Add support for .NET 8. + ## [1.1.0][1.1.0] - 2023-05-02 - Add support for caller information (class, method, file, line) through the [Serilog.Enrichers.WithCaller](https://www.nuget.org/packages/Serilog.Enrichers.WithCaller/) package. @@ -84,6 +88,7 @@ Still trying to figure out how to make everything fit together with [MinVer](htt - Implement log4j compatibility mode. +[Unreleased]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.1.0...HEAD [1.1.0]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.0.2...1.1.0 [1.0.2]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.0.1...1.0.2 [1.0.1]: https://github.com/serilog-contrib/serilog-formatting-log4net/compare/1.0.0...1.0.1 diff --git a/global.json b/global.json index f81d277..09fb573 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/global", "sdk": { - "version": "6.0.400", + "version": "8.0.100", "allowPrerelease": false, "rollForward": "latestFeature" } diff --git a/src/Log4NetTextFormatter.cs b/src/Log4NetTextFormatter.cs index dfa2890..a5099fe 100644 --- a/src/Log4NetTextFormatter.cs +++ b/src/Log4NetTextFormatter.cs @@ -19,15 +19,15 @@ public class Log4NetTextFormatter : ITextFormatter /// /// The characters that must be escaped inside an XML element. Used when is . /// - private static readonly char[] XmlElementCharactersToEscape = { '&', '<', '>' }; + private static readonly char[] XmlElementCharactersToEscape = [ '&', '<', '>' ]; /// /// The Serilog properties which have a special mapping in a log4net event and must not be part of the log4net:properties element. /// - private static readonly string[] SpecialProperties = { + private static readonly string[] SpecialProperties = [ Constants.SourceContextPropertyName, OutputProperties.MessagePropertyName, ThreadIdPropertyName, UserNamePropertyName, MachineNamePropertyName, CallerPropertyName - }; + ]; /// /// The name of the thread id property, set by Serilog.Enrichers.Thread @@ -93,6 +93,7 @@ public Log4NetTextFormatter(Action? configur /// The event to format. /// The output. /// If either or is null. + [SuppressMessage("Maintainability", "CA1510:Use ArgumentNullException throw helper", Justification = "Does not exist on .NET Standard 2.0")] public void Format(LogEvent logEvent, TextWriter output) { if (logEvent == null) @@ -113,7 +114,9 @@ public void Format(LogEvent logEvent, TextWriter output) // The resulting XML is impossible to write with a standard compliant XML writer such as XmlWriter. // That's why we write the event in a StringWriter then massage the output to remove the xmlns:log4j attribute to match log4j output. // The XML fragment becomes valid when surrounded by an external entity, see https://github.com/apache/log4j/blob/v1_2_17/src/main/java/org/apache/log4j/xml/XMLLayout.java#L31-L49 - const string log4JNamespaceAttribute = @" xmlns:log4j=""http://jakarta.apache.org/log4j/"""; + const string log4JNamespaceAttribute = """ + xmlns:log4j="http://jakarta.apache.org/log4j/" + """; var xmlString = ((StringWriter)xmlWriterOutput).ToString(); var i = xmlString.IndexOf(log4JNamespaceAttribute, StringComparison.Ordinal); #if NETSTANDARD2_0 @@ -145,7 +148,7 @@ private void WriteEvent(LogEvent logEvent, XmlWriter writer) WriteDomainAndUserName(logEvent, writer); var properties = logEvent.Properties.Where(e => !SpecialProperties.Contains(e.Key, StringComparer.Ordinal)).ToList(); var hasMachineNameProperty = logEvent.Properties.TryGetValue(MachineNamePropertyName, out var machineNameProperty) && machineNameProperty is ScalarValue { Value: not null }; - if (properties.Any() || hasMachineNameProperty) + if (properties.Count > 0 || hasMachineNameProperty) { WriteProperties(logEvent, writer, properties, machineNameProperty); } @@ -165,7 +168,12 @@ private static void WriteDomainAndUserName(LogEvent logEvent, XmlWriter writer) if (logEvent.Properties.TryGetValue(UserNamePropertyName, out var propertyValue) && propertyValue is ScalarValue { Value: string userNameProperty }) { // See https://github.com/serilog/serilog-enrichers-environment/blob/3fc7cf78c5f34816633000ae74d846033498e44b/src/Serilog.Enrichers.Environment/Enrichers/EnvironmentUserNameEnricher.cs#L53 - var separatorIndex = userNameProperty.IndexOf(@"\", StringComparison.OrdinalIgnoreCase); +#if NETSTANDARD + const string backslash = @"\"; +#else + const char backslash = '\\'; +#endif + var separatorIndex = userNameProperty.IndexOf(backslash, StringComparison.OrdinalIgnoreCase); if (separatorIndex != -1) { writer.WriteAttributeString("domain", userNameProperty.Substring(0, separatorIndex)); diff --git a/src/Log4NetTextFormatterOptions.cs b/src/Log4NetTextFormatterOptions.cs index 618f41b..80f7ad5 100644 --- a/src/Log4NetTextFormatterOptions.cs +++ b/src/Log4NetTextFormatterOptions.cs @@ -6,7 +6,7 @@ namespace Serilog.Formatting.Log4Net; /// /// Options for configuring the XML format produced by . /// -internal class Log4NetTextFormatterOptions +internal sealed class Log4NetTextFormatterOptions { internal Log4NetTextFormatterOptions(IFormatProvider? formatProvider, CDataMode cDataMode, XmlQualifiedName? xmlNamespace, XmlWriterSettings xmlWriterSettings, PropertyFilter filterProperty, ExceptionFormatter formatException) { diff --git a/src/Serilog.Formatting.Log4Net.csproj b/src/Serilog.Formatting.Log4Net.csproj index 7f57ace..0e1b3e5 100644 --- a/src/Serilog.Formatting.Log4Net.csproj +++ b/src/Serilog.Formatting.Log4Net.csproj @@ -1,11 +1,11 @@ - netstandard2.0;net6.0 + net8.0;net6.0;netstandard2.0 - 10.0 + 12 enable All true @@ -57,7 +57,6 @@ - diff --git a/src/packages.lock.json b/src/packages.lock.json index 85e8784..c39a17b 100644 --- a/src/packages.lock.json +++ b/src/packages.lock.json @@ -2,16 +2,6 @@ "version": 1, "dependencies": { ".NETStandard,Version=v2.0": { - "Microsoft.SourceLink.GitHub": { - "type": "Direct", - "requested": "[1.1.1, )", - "resolved": "1.1.1", - "contentHash": "IaJGnOv/M7UQjRJks7B6p7pbPnOwisYGOIzqCz5ilGFTApZ3ktOR+6zJ12ZRPInulBmdAf1SrGdDG2MU8g6XTw==", - "dependencies": { - "Microsoft.Build.Tasks.Git": "1.1.1", - "Microsoft.SourceLink.Common": "1.1.1" - } - }, "MinVer": { "type": "Direct", "requested": "[4.3.0, )", @@ -46,11 +36,6 @@ "System.Threading": "4.0.11" } }, - "Microsoft.Build.Tasks.Git": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "AT3HlgTjsqHnWpBHSNeR0KxbLZD7bztlZVj7I8vgeYG9SYqbeFGh0TM/KVtC6fg53nrWHl3VfZFvb5BiQFcY6Q==" - }, "Microsoft.CSharp": { "type": "Transitive", "resolved": "4.0.1", @@ -84,11 +69,6 @@ "resolved": "1.0.1", "contentHash": "rkn+fKobF/cbWfnnfBOQHKVKIOpxMZBvlSHkqDWgBpwGDcLRduvs3D9OLGeV6GWGvVwNlVi2CBbTjuPmtHvyNw==" }, - "Microsoft.SourceLink.Common": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "WMcGpWKrmJmzrNeuaEb23bEMnbtR/vLmvZtkAP5qWu7vQsY59GqfRJd65sFpBszbd2k/bQ8cs8eWawQKAabkVg==" - }, "System.Collections": { "type": "Transitive", "resolved": "4.0.11", @@ -374,16 +354,349 @@ } }, "net6.0": { - "Microsoft.SourceLink.GitHub": { + "MinVer": { + "type": "Direct", + "requested": "[4.3.0, )", + "resolved": "4.3.0", + "contentHash": "YNVAW3loCFW4kTwensApaZUl+7xREK75QQNOFSbsbXx2sCSm9/IHBjUHsJGn3u0UA5r/sAqrdYBNUlOFfLhUrA==" + }, + "Serilog": { "type": "Direct", - "requested": "[1.1.1, )", - "resolved": "1.1.1", - "contentHash": "IaJGnOv/M7UQjRJks7B6p7pbPnOwisYGOIzqCz5ilGFTApZ3ktOR+6zJ12ZRPInulBmdAf1SrGdDG2MU8g6XTw==", + "requested": "[2.0.0, )", + "resolved": "2.0.0", + "contentHash": "PKR/FMxfHOhX1p3Qs54Uv9dJEC09sI91cVz39Jt/2f/BpCYHTt9F1RpogSJTFU9xxW6j9FHd+P7aBcC0qMeuqg==", + "dependencies": { + "Microsoft.CSharp": "4.0.1", + "System.Collections": "4.0.11", + "System.Dynamic.Runtime": "4.0.11", + "System.Globalization": "4.0.11", + "System.Linq": "4.1.0", + "System.Reflection": "4.1.0", + "System.Reflection.Extensions": "4.0.1", + "System.Runtime": "4.1.0", + "System.Runtime.Extensions": "4.1.0", + "System.Text.RegularExpressions": "4.1.0", + "System.Threading": "4.0.11" + } + }, + "Microsoft.CSharp": { + "type": "Transitive", + "resolved": "4.0.1", + "contentHash": "17h8b5mXa87XYKrrVqdgZ38JefSUqLChUQpXgSnpzsM0nDOhE40FTeNWOJ/YmySGV6tG6T8+hjz6vxbknHJr6A==", + "dependencies": { + "System.Collections": "4.0.11", + "System.Diagnostics.Debug": "4.0.11", + "System.Dynamic.Runtime": "4.0.11", + "System.Globalization": "4.0.11", + "System.Linq": "4.1.0", + "System.Linq.Expressions": "4.1.0", + "System.ObjectModel": "4.0.12", + "System.Reflection": "4.1.0", + "System.Reflection.Extensions": "4.0.1", + "System.Reflection.Primitives": "4.0.1", + "System.Reflection.TypeExtensions": "4.1.0", + "System.Resources.ResourceManager": "4.0.1", + "System.Runtime": "4.1.0", + "System.Runtime.Extensions": "4.1.0", + "System.Runtime.InteropServices": "4.1.0", + "System.Threading": "4.0.11" + } + }, + "Microsoft.NETCore.Platforms": { + "type": "Transitive", + "resolved": "1.0.1", + "contentHash": "2G6OjjJzwBfNOO8myRV/nFrbTw5iA+DEm0N+qUqhrOmaVtn4pC77h38I1jsXGw5VH55+dPfQsqHD0We9sCl9FQ==" + }, + "Microsoft.NETCore.Targets": { + "type": "Transitive", + "resolved": "1.0.1", + "contentHash": "rkn+fKobF/cbWfnnfBOQHKVKIOpxMZBvlSHkqDWgBpwGDcLRduvs3D9OLGeV6GWGvVwNlVi2CBbTjuPmtHvyNw==" + }, + "System.Collections": { + "type": "Transitive", + "resolved": "4.0.11", + "contentHash": "YUJGz6eFKqS0V//mLt25vFGrrCvOnsXjlvFQs+KimpwNxug9x0Pzy4PlFMU3Q2IzqAa9G2L4LsK3+9vCBK7oTg==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Diagnostics.Debug": { + "type": "Transitive", + "resolved": "4.0.11", + "contentHash": "w5U95fVKHY4G8ASs/K5iK3J5LY+/dLFd4vKejsnI/ZhBsWS9hQakfx3Zr7lRWKg4tAw9r4iktyvsTagWkqYCiw==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Dynamic.Runtime": { + "type": "Transitive", + "resolved": "4.0.11", + "contentHash": "db34f6LHYM0U0JpE+sOmjar27BnqTVkbLJhgfwMpTdgTigG/Hna3m2MYVwnFzGGKnEJk2UXFuoVTr8WUbU91/A==", + "dependencies": { + "System.Collections": "4.0.11", + "System.Diagnostics.Debug": "4.0.11", + "System.Globalization": "4.0.11", + "System.Linq": "4.1.0", + "System.Linq.Expressions": "4.1.0", + "System.ObjectModel": "4.0.12", + "System.Reflection": "4.1.0", + "System.Reflection.Emit": "4.0.1", + "System.Reflection.Emit.ILGeneration": "4.0.1", + "System.Reflection.Primitives": "4.0.1", + "System.Reflection.TypeExtensions": "4.1.0", + "System.Resources.ResourceManager": "4.0.1", + "System.Runtime": "4.1.0", + "System.Runtime.Extensions": "4.1.0", + "System.Threading": "4.0.11" + } + }, + "System.Globalization": { + "type": "Transitive", + "resolved": "4.0.11", + "contentHash": "B95h0YLEL2oSnwF/XjqSWKnwKOy/01VWkNlsCeMTFJLLabflpGV26nK164eRs5GiaRSBGpOxQ3pKoSnnyZN5pg==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.IO": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "3KlTJceQc3gnGIaHZ7UBZO26SHL1SHE4ddrmiwumFnId+CEHP+O8r386tZKaE6zlk5/mF8vifMBzHj9SaXN+mQ==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Runtime": "4.1.0", + "System.Text.Encoding": "4.0.11", + "System.Threading.Tasks": "4.0.11" + } + }, + "System.Linq": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "bQ0iYFOQI0nuTnt+NQADns6ucV4DUvMdwN6CbkB1yj8i7arTGiTN5eok1kQwdnnNWSDZfIUySQY+J3d5KjWn0g==", + "dependencies": { + "System.Collections": "4.0.11", + "System.Diagnostics.Debug": "4.0.11", + "System.Resources.ResourceManager": "4.0.1", + "System.Runtime": "4.1.0", + "System.Runtime.Extensions": "4.1.0" + } + }, + "System.Linq.Expressions": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "I+y02iqkgmCAyfbqOmSDOgqdZQ5tTj80Akm5BPSS8EeB0VGWdy6X1KCoYe8Pk6pwDoAKZUOdLVxnTJcExiv5zw==", + "dependencies": { + "System.Collections": "4.0.11", + "System.Diagnostics.Debug": "4.0.11", + "System.Globalization": "4.0.11", + "System.IO": "4.1.0", + "System.Linq": "4.1.0", + "System.ObjectModel": "4.0.12", + "System.Reflection": "4.1.0", + "System.Reflection.Emit": "4.0.1", + "System.Reflection.Emit.ILGeneration": "4.0.1", + "System.Reflection.Emit.Lightweight": "4.0.1", + "System.Reflection.Extensions": "4.0.1", + "System.Reflection.Primitives": "4.0.1", + "System.Reflection.TypeExtensions": "4.1.0", + "System.Resources.ResourceManager": "4.0.1", + "System.Runtime": "4.1.0", + "System.Runtime.Extensions": "4.1.0", + "System.Threading": "4.0.11" + } + }, + "System.ObjectModel": { + "type": "Transitive", + "resolved": "4.0.12", + "contentHash": "tAgJM1xt3ytyMoW4qn4wIqgJYm7L7TShRZG4+Q4Qsi2PCcj96pXN7nRywS9KkB3p/xDUjc2HSwP9SROyPYDYKQ==", + "dependencies": { + "System.Collections": "4.0.11", + "System.Diagnostics.Debug": "4.0.11", + "System.Resources.ResourceManager": "4.0.1", + "System.Runtime": "4.1.0", + "System.Threading": "4.0.11" + } + }, + "System.Reflection": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "JCKANJ0TI7kzoQzuwB/OoJANy1Lg338B6+JVacPl4TpUwi3cReg3nMLplMq2uqYfHFQpKIlHAUVAJlImZz/4ng==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.IO": "4.1.0", + "System.Reflection.Primitives": "4.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Reflection.Emit": { + "type": "Transitive", + "resolved": "4.0.1", + "contentHash": "P2wqAj72fFjpP6wb9nSfDqNBMab+2ovzSDzUZK7MVIm54tBJEPr9jWfSjjoTpPwj1LeKcmX3vr0ttyjSSFM47g==", + "dependencies": { + "System.IO": "4.1.0", + "System.Reflection": "4.1.0", + "System.Reflection.Emit.ILGeneration": "4.0.1", + "System.Reflection.Primitives": "4.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Reflection.Emit.ILGeneration": { + "type": "Transitive", + "resolved": "4.0.1", + "contentHash": "Ov6dU8Bu15Bc7zuqttgHF12J5lwSWyTf1S+FJouUXVMSqImLZzYaQ+vRr1rQ0OZ0HqsrwWl4dsKHELckQkVpgA==", + "dependencies": { + "System.Reflection": "4.1.0", + "System.Reflection.Primitives": "4.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Reflection.Emit.Lightweight": { + "type": "Transitive", + "resolved": "4.0.1", + "contentHash": "sSzHHXueZ5Uh0OLpUQprhr+ZYJrLPA2Cmr4gn0wj9+FftNKXx8RIMKvO9qnjk2ebPYUjZ+F2ulGdPOsvj+MEjA==", + "dependencies": { + "System.Reflection": "4.1.0", + "System.Reflection.Emit.ILGeneration": "4.0.1", + "System.Reflection.Primitives": "4.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Reflection.Extensions": { + "type": "Transitive", + "resolved": "4.0.1", + "contentHash": "GYrtRsZcMuHF3sbmRHfMYpvxZoIN2bQGrYGerUiWLEkqdEUQZhH3TRSaC/oI4wO0II1RKBPlpIa1TOMxIcOOzQ==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Reflection": "4.1.0", + "System.Runtime": "4.1.0" + } + }, + "System.Reflection.Primitives": { + "type": "Transitive", + "resolved": "4.0.1", + "contentHash": "4inTox4wTBaDhB7V3mPvp9XlCbeGYWVEM9/fXALd52vNEAVisc1BoVWQPuUuD0Ga//dNbA/WeMy9u9mzLxGTHQ==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Reflection.TypeExtensions": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "tsQ/ptQ3H5FYfON8lL4MxRk/8kFyE0A+tGPXmVP967cT/gzLHYxIejIYSxp4JmIeFHVP78g/F2FE1mUUTbDtrg==", + "dependencies": { + "System.Reflection": "4.1.0", + "System.Runtime": "4.1.0" + } + }, + "System.Resources.ResourceManager": { + "type": "Transitive", + "resolved": "4.0.1", + "contentHash": "TxwVeUNoTgUOdQ09gfTjvW411MF+w9MBYL7AtNVc+HtBCFlutPLhUCdZjNkjbhj3bNQWMdHboF0KIWEOjJssbA==", "dependencies": { - "Microsoft.Build.Tasks.Git": "1.1.1", - "Microsoft.SourceLink.Common": "1.1.1" + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Globalization": "4.0.11", + "System.Reflection": "4.1.0", + "System.Runtime": "4.1.0" } }, + "System.Runtime": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "v6c/4Yaa9uWsq+JMhnOFewrYkgdNHNG2eMKuNqRn8P733rNXeRCGvV5FkkjBXn2dbVkPXOsO0xjsEeM1q2zC0g==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1" + } + }, + "System.Runtime.Extensions": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "CUOHjTT/vgP0qGW22U4/hDlOqXmcPq5YicBaXdUR2UiUoLwBT+olO6we4DVbq57jeX5uXH2uerVZhf0qGj+sVQ==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Runtime.Handles": { + "type": "Transitive", + "resolved": "4.0.1", + "contentHash": "nCJvEKguXEvk2ymk1gqj625vVnlK3/xdGzx0vOKicQkoquaTBJTP13AIYkocSUwHCLNBwUbXTqTWGDxBTWpt7g==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Runtime.InteropServices": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "16eu3kjHS633yYdkjwShDHZLRNMKVi/s0bY8ODiqJ2RfMhDMAwxZaUaWVnZ2P71kr/or+X9o/xFWtNqz8ivieQ==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Reflection": "4.1.0", + "System.Reflection.Primitives": "4.0.1", + "System.Runtime": "4.1.0", + "System.Runtime.Handles": "4.0.1" + } + }, + "System.Text.Encoding": { + "type": "Transitive", + "resolved": "4.0.11", + "contentHash": "U3gGeMlDZXxCEiY4DwVLSacg+DFWCvoiX+JThA/rvw37Sqrku7sEFeVBBBMBnfB6FeZHsyDx85HlKL19x0HtZA==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Runtime": "4.1.0" + } + }, + "System.Text.RegularExpressions": { + "type": "Transitive", + "resolved": "4.1.0", + "contentHash": "i88YCXpRTjCnoSQZtdlHkAOx4KNNik4hMy83n0+Ftlb7jvV6ZiZWMpnEZHhjBp6hQVh8gWd/iKNPzlPF7iyA2g==", + "dependencies": { + "System.Collections": "4.0.11", + "System.Globalization": "4.0.11", + "System.Resources.ResourceManager": "4.0.1", + "System.Runtime": "4.1.0", + "System.Runtime.Extensions": "4.1.0", + "System.Threading": "4.0.11" + } + }, + "System.Threading": { + "type": "Transitive", + "resolved": "4.0.11", + "contentHash": "N+3xqIcg3VDKyjwwCGaZ9HawG9aC6cSDI+s7ROma310GQo8vilFZa86hqKppwTHleR/G0sfOzhvgnUxWCR/DrQ==", + "dependencies": { + "System.Runtime": "4.1.0", + "System.Threading.Tasks": "4.0.11" + } + }, + "System.Threading.Tasks": { + "type": "Transitive", + "resolved": "4.0.11", + "contentHash": "k1S4Gc6IGwtHGT8188RSeGaX86Qw/wnrgNLshJvsdNUOPP9etMmo8S07c+UlOAx4K/xLuN9ivA1bD0LVurtIxQ==", + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1", + "Microsoft.NETCore.Targets": "1.0.1", + "System.Runtime": "4.1.0" + } + } + }, + "net8.0": { "MinVer": { "type": "Direct", "requested": "[4.3.0, )", @@ -409,11 +722,6 @@ "System.Threading": "4.0.11" } }, - "Microsoft.Build.Tasks.Git": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "AT3HlgTjsqHnWpBHSNeR0KxbLZD7bztlZVj7I8vgeYG9SYqbeFGh0TM/KVtC6fg53nrWHl3VfZFvb5BiQFcY6Q==" - }, "Microsoft.CSharp": { "type": "Transitive", "resolved": "4.0.1", @@ -447,11 +755,6 @@ "resolved": "1.0.1", "contentHash": "rkn+fKobF/cbWfnnfBOQHKVKIOpxMZBvlSHkqDWgBpwGDcLRduvs3D9OLGeV6GWGvVwNlVi2CBbTjuPmtHvyNw==" }, - "Microsoft.SourceLink.Common": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "WMcGpWKrmJmzrNeuaEb23bEMnbtR/vLmvZtkAP5qWu7vQsY59GqfRJd65sFpBszbd2k/bQ8cs8eWawQKAabkVg==" - }, "System.Collections": { "type": "Transitive", "resolved": "4.0.11", diff --git a/tests/Log4NetTextFormatterTest.cs b/tests/Log4NetTextFormatterTest.cs index 0fd7ce1..1732077 100644 --- a/tests/Log4NetTextFormatterTest.cs +++ b/tests/Log4NetTextFormatterTest.cs @@ -27,7 +27,7 @@ public static Exception SetStackTrace(this Exception exception, string stackTrac } } -public class Log4NetTextFormatterTest : IDisposable +public sealed class Log4NetTextFormatterTest : IDisposable { private readonly TextWriter _selfLogWriter; private string? SelfLogValue => _selfLogWriter.ToString(); @@ -313,7 +313,7 @@ public Task Log4JCompatibility(bool useStaticInstance) // Arrange using var output = new StringWriter(); var logEvent = CreateLogEvent( - exception: new Exception("An error occurred").SetStackTrace(@" at Serilog.Formatting.Log4Net.Tests.Log4NetTextFormatterTest.BasicMessage_WithException() in Log4NetTextFormatterTest.cs:123"), + exception: new Exception("An error occurred").SetStackTrace(" at Serilog.Formatting.Log4Net.Tests.Log4NetTextFormatterTest.BasicMessage_WithException() in Log4NetTextFormatterTest.cs:123"), properties: new LogEventProperty("π", new ScalarValue(3.14m)) ); var formatter = useStaticInstance ? Log4NetTextFormatter.Log4JFormatter : new Log4NetTextFormatter(c => c.UseLog4JCompatibility()); @@ -346,10 +346,10 @@ public Task TwoProperties() { // Arrange using var output = new StringWriter(); - var logEvent = CreateLogEvent(properties: new[]{ + var logEvent = CreateLogEvent(properties: [ new LogEventProperty("one", new ScalarValue(1)), new LogEventProperty("two", new ScalarValue(2)), - }); + ]); var formatter = new Log4NetTextFormatter(); // Act @@ -364,10 +364,10 @@ public Task TwoPropertiesOneNull() { // Arrange using var output = new StringWriter(); - var logEvent = CreateLogEvent(properties: new[]{ + var logEvent = CreateLogEvent(properties: [ new LogEventProperty("n/a", new ScalarValue(null)), - new LogEventProperty("one", new ScalarValue(1)), - }); + new LogEventProperty("one", new ScalarValue(1)) + ]); var formatter = new Log4NetTextFormatter(); // Act @@ -382,10 +382,10 @@ public Task FilterProperty() { // Arrange using var output = new StringWriter(); - var logEvent = CreateLogEvent(properties: new[]{ + var logEvent = CreateLogEvent(properties: [ new LogEventProperty("one", new ScalarValue(1)), new LogEventProperty("two", new ScalarValue(2)), - }); + ]); var formatter = new Log4NetTextFormatter(options => options.UsePropertyFilter((_, propertyName) => propertyName != "one")); // Act @@ -400,10 +400,10 @@ public Task FilterPropertyThrowing() { // Arrange using var output = new StringWriter(); - var logEvent = CreateLogEvent(properties: new[]{ + var logEvent = CreateLogEvent(properties: [ new LogEventProperty("one", new ScalarValue(1)), new LogEventProperty("two", new ScalarValue(2)), - }); + ]); var formatter = new Log4NetTextFormatter(options => options.UsePropertyFilter((_, propertyName) => { if (propertyName == "one") @@ -442,7 +442,7 @@ public Task Exception() { // Arrange using var output = new StringWriter(); - var logEvent = CreateLogEvent(exception: new Exception("An error occurred").SetStackTrace(@" at Serilog.Formatting.Log4Net.Tests.Log4NetTextFormatterTest.BasicMessage_WithException() in Log4NetTextFormatterTest.cs:123")); + var logEvent = CreateLogEvent(exception: new Exception("An error occurred").SetStackTrace(" at Serilog.Formatting.Log4Net.Tests.Log4NetTextFormatterTest.BasicMessage_WithException() in Log4NetTextFormatterTest.cs:123")); var formatter = new Log4NetTextFormatter(); // Act @@ -517,8 +517,8 @@ public Task ThreadIdProperty(int? threadId) [Theory] [InlineData(null)] - [InlineData(@"")] - [InlineData(@"TheUser")] + [InlineData("")] + [InlineData("TheUser")] [InlineData(@"TheDomain\TheUser")] [InlineData(@"TheDomain\TheUser\Name")] public Task DomainAndUserNameProperty(string? environmentUserName) diff --git a/tests/PublicApi.net6.0.verified.cs b/tests/PublicApi.net6.0.verified.cs index 5dd9008..b7d3c2d 100644 --- a/tests/PublicApi.net6.0.verified.cs +++ b/tests/PublicApi.net6.0.verified.cs @@ -1,6 +1,6 @@ [assembly: System.CLSCompliant(true)] [assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/serilog-contrib/serilog-formatting-log4net")] -[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName="")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")] namespace Serilog.Formatting.Log4Net { public enum CDataMode diff --git a/tests/PublicApi.net8.0.verified.cs b/tests/PublicApi.net8.0.verified.cs new file mode 100644 index 0000000..f505127 --- /dev/null +++ b/tests/PublicApi.net8.0.verified.cs @@ -0,0 +1,50 @@ +[assembly: System.CLSCompliant(true)] +[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/serilog-contrib/serilog-formatting-log4net")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName=".NET 8.0")] +namespace Serilog.Formatting.Log4Net +{ + public enum CDataMode + { + Always = 0, + Never = 1, + IfNeeded = 2, + } + public delegate string ExceptionFormatter(System.Exception exception); + public enum Indentation + { + Space = 0, + Tab = 1, + } + public class IndentationSettings + { + public IndentationSettings(Serilog.Formatting.Log4Net.Indentation indentation, byte size) { } + public override string ToString() { } + } + [System.Flags] + public enum LineEnding + { + None = 0, + LineFeed = 1, + CarriageReturn = 2, + } + public class Log4NetTextFormatter : Serilog.Formatting.ITextFormatter + { + public Log4NetTextFormatter() { } + public Log4NetTextFormatter(System.Action? configureOptions) { } + public static Serilog.Formatting.Log4Net.Log4NetTextFormatter Log4JFormatter { get; } + public void Format(Serilog.Events.LogEvent logEvent, System.IO.TextWriter output) { } + } + public class Log4NetTextFormatterOptionsBuilder + { + public Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder UseCDataMode(Serilog.Formatting.Log4Net.CDataMode cDataMode) { } + public Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder UseExceptionFormatter(Serilog.Formatting.Log4Net.ExceptionFormatter formatException) { } + public Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder UseFormatProvider(System.IFormatProvider? formatProvider) { } + public Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder UseIndentationSettings(Serilog.Formatting.Log4Net.IndentationSettings indentationSettings) { } + public Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder UseLineEnding(Serilog.Formatting.Log4Net.LineEnding lineEnding) { } + public void UseLog4JCompatibility() { } + public Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder UseNoIndentation() { } + public Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder UseNoXmlNamespace() { } + public Serilog.Formatting.Log4Net.Log4NetTextFormatterOptionsBuilder UsePropertyFilter(Serilog.Formatting.Log4Net.PropertyFilter filterProperty) { } + } + public delegate bool PropertyFilter(Serilog.Events.LogEvent logEvent, string propertyName); +} \ No newline at end of file diff --git a/tests/PublicApi.netstandard2.0.verified.cs b/tests/PublicApi.netstandard2.0.verified.cs index fe5b4fe..afa946b 100644 --- a/tests/PublicApi.netstandard2.0.verified.cs +++ b/tests/PublicApi.netstandard2.0.verified.cs @@ -1,6 +1,6 @@ [assembly: System.CLSCompliant(true)] [assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/serilog-contrib/serilog-formatting-log4net")] -[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName="")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")] namespace Serilog.Formatting.Log4Net { public enum CDataMode diff --git a/tests/Serilog.Formatting.Log4Net.Tests.csproj b/tests/Serilog.Formatting.Log4Net.Tests.csproj index 83f228d..516eb9c 100644 --- a/tests/Serilog.Formatting.Log4Net.Tests.csproj +++ b/tests/Serilog.Formatting.Log4Net.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable false