From bb6035929e3639267f5bd8abe99b812a5a908dfb Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Fri, 6 Sep 2024 00:59:51 +0200 Subject: [PATCH 01/12] #175 Dropping support for legacy serialization --- src/build-preview.ps1 | 2 +- src/log4net/Appender/FileAppender.cs | 2 +- .../Config/AliasRepositoryAttribute.cs | 2 +- src/log4net/Config/PluginAttribute.cs | 2 +- src/log4net/Config/RepositoryAttribute.cs | 2 +- .../SecurityContextProviderAttribute.cs | 2 +- .../Config/XmlConfiguratorAttribute.cs | 2 +- src/log4net/Core/Level.cs | 4 ++-- src/log4net/Core/LocationInfo.cs | 4 ++-- src/log4net/Core/LogException.cs | 2 +- src/log4net/Core/LoggingEvent.cs | 4 ++-- src/log4net/Core/MethodItem.cs | 2 +- src/log4net/Core/Serializable.cs | 24 +++++++++++++++++++ src/log4net/Core/StackFrameItem.cs | 2 +- src/log4net/Util/EmptyCollection.cs | 2 +- src/log4net/Util/EmptyDictionary.cs | 2 +- src/log4net/Util/PropertiesDictionary.cs | 4 ++-- .../Util/ReadOnlyPropertiesDictionary.cs | 4 ++-- .../ConversionNotSupportedException.cs | 2 +- src/site/xdoc/release/release-notes.xml | 4 ++++ 20 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 src/log4net/Core/Serializable.cs diff --git a/src/build-preview.ps1 b/src/build-preview.ps1 index c824735b..0c71fb20 100644 --- a/src/build-preview.ps1 +++ b/src/build-preview.ps1 @@ -1 +1 @@ -dotnet build -c Release '-p:GeneratePackages=true;VersionSuffix=preview.2' ./log4net/log4net.csproj \ No newline at end of file +dotnet build -c Release '-p:GeneratePackages=true;VersionSuffix=preview.4' ./log4net/log4net.csproj \ No newline at end of file diff --git a/src/log4net/Appender/FileAppender.cs b/src/log4net/Appender/FileAppender.cs index 15131146..5be9ab8e 100644 --- a/src/log4net/Appender/FileAppender.cs +++ b/src/log4net/Appender/FileAppender.cs @@ -86,7 +86,7 @@ public class FileAppender : TextWriterAppender /// private sealed class LockingStream : Stream, IDisposable { - [Serializable] + [Log4NetSerializable] public sealed class LockStateException : LogException { public LockStateException(string message) diff --git a/src/log4net/Config/AliasRepositoryAttribute.cs b/src/log4net/Config/AliasRepositoryAttribute.cs index 39373331..2d7002d0 100644 --- a/src/log4net/Config/AliasRepositoryAttribute.cs +++ b/src/log4net/Config/AliasRepositoryAttribute.cs @@ -41,7 +41,7 @@ namespace log4net.Config /// Nicko Cadell /// Gert Driesen [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - [Serializable] + [Log4NetSerializable] public sealed class AliasRepositoryAttribute : Attribute { /// diff --git a/src/log4net/Config/PluginAttribute.cs b/src/log4net/Config/PluginAttribute.cs index 9ef26e61..c9110b24 100644 --- a/src/log4net/Config/PluginAttribute.cs +++ b/src/log4net/Config/PluginAttribute.cs @@ -39,7 +39,7 @@ namespace log4net.Config /// Nicko Cadell /// Gert Driesen [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - [Serializable] + [Log4NetSerializable] public sealed class PluginAttribute : Attribute, IPluginFactory { /// diff --git a/src/log4net/Config/RepositoryAttribute.cs b/src/log4net/Config/RepositoryAttribute.cs index 59514517..ccf4efb7 100644 --- a/src/log4net/Config/RepositoryAttribute.cs +++ b/src/log4net/Config/RepositoryAttribute.cs @@ -42,7 +42,7 @@ namespace log4net.Config /// Nicko Cadell /// Gert Driesen [AttributeUsage(AttributeTargets.Assembly)] - [Serializable] + [Log4NetSerializable] public sealed class RepositoryAttribute : Attribute { /// diff --git a/src/log4net/Config/SecurityContextProviderAttribute.cs b/src/log4net/Config/SecurityContextProviderAttribute.cs index e82e858e..e8edeee2 100644 --- a/src/log4net/Config/SecurityContextProviderAttribute.cs +++ b/src/log4net/Config/SecurityContextProviderAttribute.cs @@ -42,7 +42,7 @@ namespace log4net.Config /// /// Nicko Cadell [AttributeUsage(AttributeTargets.Assembly)] - [Serializable] + [Log4NetSerializable] public sealed class SecurityContextProviderAttribute : ConfiguratorAttribute { /// diff --git a/src/log4net/Config/XmlConfiguratorAttribute.cs b/src/log4net/Config/XmlConfiguratorAttribute.cs index aee8389c..24411cbd 100644 --- a/src/log4net/Config/XmlConfiguratorAttribute.cs +++ b/src/log4net/Config/XmlConfiguratorAttribute.cs @@ -76,7 +76,7 @@ namespace log4net.Config /// Nicko Cadell /// Gert Driesen [AttributeUsage(AttributeTargets.Assembly)] - [Serializable] + [Log4NetSerializable] public sealed class XmlConfiguratorAttribute : ConfiguratorAttribute { /// diff --git a/src/log4net/Core/Level.cs b/src/log4net/Core/Level.cs index e15078b6..3027fb58 100644 --- a/src/log4net/Core/Level.cs +++ b/src/log4net/Core/Level.cs @@ -82,8 +82,8 @@ namespace log4net.Core; /// /// Nicko Cadell /// Gert Driesen -[Serializable] -public class Level : IComparable, ISerializable, IEquatable, IComparable +[Log4NetSerializable] +public class Level : IComparable, ILog4NetSerializable, IEquatable, IComparable { /// /// Constructor diff --git a/src/log4net/Core/LocationInfo.cs b/src/log4net/Core/LocationInfo.cs index 2ce29ae0..3e1c3ef0 100644 --- a/src/log4net/Core/LocationInfo.cs +++ b/src/log4net/Core/LocationInfo.cs @@ -57,8 +57,8 @@ namespace log4net.Core /// /// Nicko Cadell /// Gert Driesen - [Serializable] - public class LocationInfo : ISerializable + [Log4NetSerializable] + public class LocationInfo : ILog4NetSerializable { /// /// Constructor diff --git a/src/log4net/Core/LogException.cs b/src/log4net/Core/LogException.cs index 33a604d3..762eb384 100644 --- a/src/log4net/Core/LogException.cs +++ b/src/log4net/Core/LogException.cs @@ -34,7 +34,7 @@ namespace log4net.Core /// /// Nicko Cadell /// Gert Driesen - [Serializable] + [Log4NetSerializable] public class LogException : ApplicationException { /// diff --git a/src/log4net/Core/LoggingEvent.cs b/src/log4net/Core/LoggingEvent.cs index 48d2e25f..8cfadf51 100644 --- a/src/log4net/Core/LoggingEvent.cs +++ b/src/log4net/Core/LoggingEvent.cs @@ -164,8 +164,8 @@ public struct LoggingEventData /// Gert Driesen /// Douglas de la Torre /// Daniel Cazzulino - [Serializable] - public class LoggingEvent : ISerializable + [Log4NetSerializable] + public class LoggingEvent : ILog4NetSerializable { private static readonly Type declaringType = typeof(LoggingEvent); diff --git a/src/log4net/Core/MethodItem.cs b/src/log4net/Core/MethodItem.cs index 5e8314bb..5c8d02c6 100644 --- a/src/log4net/Core/MethodItem.cs +++ b/src/log4net/Core/MethodItem.cs @@ -28,7 +28,7 @@ namespace log4net.Core /// as that would require that the containing assembly is loaded. /// /// - [Serializable] + [Log4NetSerializable] public class MethodItem { /// diff --git a/src/log4net/Core/Serializable.cs b/src/log4net/Core/Serializable.cs new file mode 100644 index 00000000..b88f0612 --- /dev/null +++ b/src/log4net/Core/Serializable.cs @@ -0,0 +1,24 @@ +#if NET462_OR_GREATER +global using Log4NetSerializableAttribute = System.SerializableAttribute; +global using ILog4NetSerializable = System.Runtime.Serialization.ISerializable; +#else +global using Log4NetSerializableAttribute = log4net.Core.EmptyAttribute; +global using ILog4NetSerializable = log4net.Core.IEmptyInterface; +using System; +#endif + +namespace log4net.Core; +#if !NET462_OR_GREATER +/// +/// Empty Interface (as replacement for ) +/// +internal interface IEmptyInterface +{ } + +/// +/// Empty Attribute (as replacement for ) +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false)] +internal sealed class EmptyAttribute : Attribute +{ } +#endif \ No newline at end of file diff --git a/src/log4net/Core/StackFrameItem.cs b/src/log4net/Core/StackFrameItem.cs index a27d7037..6cf2f782 100644 --- a/src/log4net/Core/StackFrameItem.cs +++ b/src/log4net/Core/StackFrameItem.cs @@ -28,7 +28,7 @@ namespace log4net.Core /// Provides stack frame information without actually referencing a System.Diagnostics.StackFrame /// as that would require that the containing assembly is loaded. /// - [Serializable] + [Log4NetSerializable] public class StackFrameItem { /// diff --git a/src/log4net/Util/EmptyCollection.cs b/src/log4net/Util/EmptyCollection.cs index 708370ca..30082648 100644 --- a/src/log4net/Util/EmptyCollection.cs +++ b/src/log4net/Util/EmptyCollection.cs @@ -33,7 +33,7 @@ namespace log4net.Util /// /// Nicko Cadell /// Gert Driesen - [Serializable] + [Log4NetSerializable] public sealed class EmptyCollection : ICollection { /// diff --git a/src/log4net/Util/EmptyDictionary.cs b/src/log4net/Util/EmptyDictionary.cs index 9ed11b08..fbee5305 100644 --- a/src/log4net/Util/EmptyDictionary.cs +++ b/src/log4net/Util/EmptyDictionary.cs @@ -33,7 +33,7 @@ namespace log4net.Util /// /// Nicko Cadell /// Gert Driesen - [Serializable] + [Log4NetSerializable] public sealed class EmptyDictionary : IDictionary { /// diff --git a/src/log4net/Util/PropertiesDictionary.cs b/src/log4net/Util/PropertiesDictionary.cs index 3f2c1064..b6682b66 100644 --- a/src/log4net/Util/PropertiesDictionary.cs +++ b/src/log4net/Util/PropertiesDictionary.cs @@ -36,8 +36,8 @@ namespace log4net.Util /// /// Nicko Cadell /// Gert Driesen - [Serializable] - public sealed class PropertiesDictionary : ReadOnlyPropertiesDictionary, ISerializable, IDictionary + [Log4NetSerializable] + public sealed class PropertiesDictionary : ReadOnlyPropertiesDictionary, ILog4NetSerializable, IDictionary { /// /// Constructor diff --git a/src/log4net/Util/ReadOnlyPropertiesDictionary.cs b/src/log4net/Util/ReadOnlyPropertiesDictionary.cs index 2c347961..d2973218 100644 --- a/src/log4net/Util/ReadOnlyPropertiesDictionary.cs +++ b/src/log4net/Util/ReadOnlyPropertiesDictionary.cs @@ -40,8 +40,8 @@ namespace log4net.Util /// /// Nicko Cadell /// Gert Driesen - [Serializable] - public class ReadOnlyPropertiesDictionary : ISerializable, IDictionary, IDictionary + [Log4NetSerializable] + public class ReadOnlyPropertiesDictionary : ILog4NetSerializable, IDictionary, IDictionary { private const string ReadOnlyMessage = "This is a read-only dictionary and cannot be modified"; diff --git a/src/log4net/Util/TypeConverters/ConversionNotSupportedException.cs b/src/log4net/Util/TypeConverters/ConversionNotSupportedException.cs index 6d33310e..6a351af3 100644 --- a/src/log4net/Util/TypeConverters/ConversionNotSupportedException.cs +++ b/src/log4net/Util/TypeConverters/ConversionNotSupportedException.cs @@ -34,7 +34,7 @@ namespace log4net.Util.TypeConverters /// /// Nicko Cadell /// Gert Driesen - [Serializable] + [Log4NetSerializable] public class ConversionNotSupportedException : ApplicationException { /// diff --git a/src/site/xdoc/release/release-notes.xml b/src/site/xdoc/release/release-notes.xml index 1441b258..54ff489d 100644 --- a/src/site/xdoc/release/release-notes.xml +++ b/src/site/xdoc/release/release-notes.xml @@ -137,6 +137,10 @@ limitations under the License. log4net.Appender.NetSendAppender NetSendAdapter removed +
  • + Serializable Support removed (for .netstandard) + Removing legacy serialization from log4net +

  • From 402f8e8815a9250ebc30d55074fe5cb2e9d9aca4 Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Mon, 9 Sep 2024 11:13:12 +0200 Subject: [PATCH 02/12] fixed typo in releasing.md --- doc/RELEASING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/RELEASING.md b/doc/RELEASING.md index 0ff978c6..2c732232 100644 --- a/doc/RELEASING.md +++ b/doc/RELEASING.md @@ -31,7 +31,7 @@ release version 2.0.123: - log4net.build: update package.version property - pom.xml: update version 4. Sign release artifacts (zips & nupkg) under `build/artifacts` - - eg `gpg --argmor --output log4net-2.0.123.nupkg.asc --detach-sig log4net-2.0.123.nupkg` + - eg `gpg --armor --output log4net-2.0.123.nupkg.asc --detach-sig log4net-2.0.123.nupkg` - there is an accompanying `sign-log4net-libraries.sh` which you could invoke if you cd into the `build/artifacts` folder - I build on Windows and sign on Linux as my build machine belongs to my company From b8b97a092e0730aa89753ba085de9263f72f166d Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 18:19:39 +0200 Subject: [PATCH 03/12] removed changes.xml (was not used anymore) --- src/changes/changes.xml | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 src/changes/changes.xml diff --git a/src/changes/changes.xml b/src/changes/changes.xml deleted file mode 100644 index 96e9f02b..00000000 --- a/src/changes/changes.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Apache log4net - - - - - - \ No newline at end of file From 8327a6cc70eaf3f3d0af316f4e872d692ce6c7b7 Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 18:38:56 +0200 Subject: [PATCH 04/12] more cleanup for 3.0.0 --- log4net.snk.readme | 22 +- src/MonoForFramework.targets | 8 - tests/nant.build | 868 ----------------------------------- 3 files changed, 3 insertions(+), 895 deletions(-) delete mode 100644 tests/nant.build diff --git a/log4net.snk.readme b/log4net.snk.readme index 47642869..def35b05 100644 --- a/log4net.snk.readme +++ b/log4net.snk.readme @@ -2,27 +2,11 @@ Apache log4net Strong Name Key Readme ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The log4net release builds are strongly named using the log4net.snk key -file. This key is different from the key used to sign log4net 1.2.10 -and earlier releases. - -Starting with log4net 1.2.11 we've decided to use a key that we don't +file. Starting with log4net 1.2.11 we've decided to use a key that we don't keep secret so you can build a drop-in replacement for an official -release yourself. This means that the strong name of a log4net +release yourself. This means that the strong name of a log4net assembly no longer provides any means of checking its authenticity. The only way to ensure you are using an official release by the Apache Software Foundation is by downloading the distribution from the Apache log4net download page and verifying the PGP signature of the ZIP -archive. - -The key used to sign those older releases is not and has never been -distributed as part of the log4net source or binary downloads. - -In order to make it easier to migrate from log4net 1.2.10 to newer -releases log4net 1.2.11 we also provide builds using the key used to -sign 1.2.10. We may stop distributing these alternative builds in the -future. - -You should use the binary builds signed with log4net.snk for new -projects and only use the ones signed with "the old key" if switching -to the newer builds is not possible because other parts of your -project depend on the old strong name. +archive. \ No newline at end of file diff --git a/src/MonoForFramework.targets b/src/MonoForFramework.targets index 4209d58f..81b01e2b 100644 --- a/src/MonoForFramework.targets +++ b/src/MonoForFramework.targets @@ -7,14 +7,6 @@ /usr/lib/mono /usr/local/lib/mono - $(BaseFrameworkPathOverrideForMono)/2.0-api - $(BaseFrameworkPathOverrideForMono)/3.5-api - $(BaseFrameworkPathOverrideForMono)/4.0-api - $(BaseFrameworkPathOverrideForMono)/4.5-api - $(BaseFrameworkPathOverrideForMono)/4.5.1-api - $(BaseFrameworkPathOverrideForMono)/4.5.2-api - $(BaseFrameworkPathOverrideForMono)/4.6-api - $(BaseFrameworkPathOverrideForMono)/4.6.1-api $(BaseFrameworkPathOverrideForMono)/4.6.2-api $(BaseFrameworkPathOverrideForMono)/4.7-api $(BaseFrameworkPathOverrideForMono)/4.7.1-api diff --git a/tests/nant.build b/tests/nant.build deleted file mode 100644 index 913c8599..00000000 --- a/tests/nant.build +++ /dev/null @@ -1,868 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From b923ab6d0853c1cd44b2e370e77b198c373e5d84 Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 18:42:44 +0200 Subject: [PATCH 05/12] fix JSONArgsRecommended --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8a59a8a7..64516af0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,5 +32,5 @@ ENV PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools" ADD . /logging-log4net RUN dotnet restore /logging-log4net/src/log4net.sln -RUN dotnet build /logging-log4net/src/log4net.sln -CMD /bin/bash \ No newline at end of file +RUN dotnet build -c Release /logging-log4net/src/log4net.sln +CMD [/bin/bash] \ No newline at end of file From bf68ec46456149b3bcc8961f7dfc02ae55c28b60 Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 18:48:39 +0200 Subject: [PATCH 06/12] fix JSONArgsRecommended --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 64516af0..4fae004d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,4 +33,5 @@ ENV PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools" ADD . /logging-log4net RUN dotnet restore /logging-log4net/src/log4net.sln RUN dotnet build -c Release /logging-log4net/src/log4net.sln -CMD [/bin/bash] \ No newline at end of file +SHELL ["/bin/bash"] +ENTRYPOINT echo "you can start the tests with: dotnet test /logging-log4net/src/log4net.sln" \ No newline at end of file From 938db5ea7e6ff207de038afb60d1a3009c7f6fd9 Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 18:55:43 +0200 Subject: [PATCH 07/12] fix JSONArgsRecommended --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4fae004d..1936fa75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,4 +34,4 @@ ADD . /logging-log4net RUN dotnet restore /logging-log4net/src/log4net.sln RUN dotnet build -c Release /logging-log4net/src/log4net.sln SHELL ["/bin/bash"] -ENTRYPOINT echo "you can start the tests with: dotnet test /logging-log4net/src/log4net.sln" \ No newline at end of file +ENTRYPOINT echo "hello world" \ No newline at end of file From 428400a2f0eb2cbf5013caa2f5060e5b8d38aef8 Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 18:57:35 +0200 Subject: [PATCH 08/12] fix JSONArgsRecommended --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1936fa75..b018427e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,5 +33,4 @@ ENV PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools" ADD . /logging-log4net RUN dotnet restore /logging-log4net/src/log4net.sln RUN dotnet build -c Release /logging-log4net/src/log4net.sln -SHELL ["/bin/bash"] -ENTRYPOINT echo "hello world" \ No newline at end of file +CMD ["/bin/bash"] \ No newline at end of file From 1bc5dbdcde68a84ad702a4627bbe9f77ebb6dda4 Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 19:24:02 +0200 Subject: [PATCH 09/12] fix tests for mono --- src/log4net.Tests/Appender/RollingFileAppenderTest.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/log4net.Tests/Appender/RollingFileAppenderTest.cs b/src/log4net.Tests/Appender/RollingFileAppenderTest.cs index 25da7890..828dbdc3 100644 --- a/src/log4net.Tests/Appender/RollingFileAppenderTest.cs +++ b/src/log4net.Tests/Appender/RollingFileAppenderTest.cs @@ -41,6 +41,8 @@ namespace log4net.Tests.Appender [TestFixture] public sealed class RollingFileAppenderTest { + private static readonly bool isMono = Type.GetType("Mono.Runtime") is not null; + private const string c_fileName = "test_41d3d834_4320f4da.log"; private const string c_testMessage98Chars = @@ -1457,8 +1459,11 @@ public void TestExclusiveLockLocks() } catch (IOException e1) { - Assert.AreEqual("The process cannot access the file ", e1.Message.Substring(0, 35), + if (!isMono) + { + Assert.AreEqual("The process cannot access the file ", e1.Message.Substring(0, 35), "Unexpected exception"); + } locked = true; } From 555acfab0e26af9802909e8ecefcfe0670f1019f Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 19:27:35 +0200 Subject: [PATCH 10/12] fix tests for mono --- src/log4net.Tests/Appender/RollingFileAppenderTest.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/log4net.Tests/Appender/RollingFileAppenderTest.cs b/src/log4net.Tests/Appender/RollingFileAppenderTest.cs index 828dbdc3..0a6af2f5 100644 --- a/src/log4net.Tests/Appender/RollingFileAppenderTest.cs +++ b/src/log4net.Tests/Appender/RollingFileAppenderTest.cs @@ -1444,6 +1444,10 @@ public void TestExclusiveLockRecovers() [Test] public void TestExclusiveLockLocks() { + if (!isMono) + { + Assert.Inconclusive("mono has a different behaviour"); + } string filename = "test_exclusive_lock_locks.log"; bool locked = false; @@ -1459,11 +1463,8 @@ public void TestExclusiveLockLocks() } catch (IOException e1) { - if (!isMono) - { - Assert.AreEqual("The process cannot access the file ", e1.Message.Substring(0, 35), - "Unexpected exception"); - } + Assert.AreEqual("The process cannot access the file ", e1.Message.Substring(0, 35), + "Unexpected exception"); locked = true; } From e28b036d718aced282edba619f273c56c9b51395 Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 19:30:06 +0200 Subject: [PATCH 11/12] fix tests for mono --- src/log4net.Tests/Appender/RollingFileAppenderTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/log4net.Tests/Appender/RollingFileAppenderTest.cs b/src/log4net.Tests/Appender/RollingFileAppenderTest.cs index 0a6af2f5..037043d1 100644 --- a/src/log4net.Tests/Appender/RollingFileAppenderTest.cs +++ b/src/log4net.Tests/Appender/RollingFileAppenderTest.cs @@ -1444,7 +1444,7 @@ public void TestExclusiveLockRecovers() [Test] public void TestExclusiveLockLocks() { - if (!isMono) + if (isMono) { Assert.Inconclusive("mono has a different behaviour"); } From f64e3cf57dd542f83bc670ea5ab7d7818f26fe1a Mon Sep 17 00:00:00 2001 From: Jan Friedrich Date: Wed, 11 Sep 2024 19:45:19 +0200 Subject: [PATCH 12/12] exclude tests with different behaviour on mono --- .../Appender/RollingFileAppenderTest.cs | 16 ++++++----- .../Appender/SmtpPickupDirAppenderTest.cs | 3 +++ src/log4net.Tests/Core/LoggingEventTest.cs | 2 ++ src/log4net.Tests/Utils.cs | 27 ++++++++++++++++++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/log4net.Tests/Appender/RollingFileAppenderTest.cs b/src/log4net.Tests/Appender/RollingFileAppenderTest.cs index 037043d1..32ab4d8c 100644 --- a/src/log4net.Tests/Appender/RollingFileAppenderTest.cs +++ b/src/log4net.Tests/Appender/RollingFileAppenderTest.cs @@ -41,8 +41,6 @@ namespace log4net.Tests.Appender [TestFixture] public sealed class RollingFileAppenderTest { - private static readonly bool isMono = Type.GetType("Mono.Runtime") is not null; - private const string c_fileName = "test_41d3d834_4320f4da.log"; private const string c_testMessage98Chars = @@ -1381,6 +1379,7 @@ private static void AssertFileEquals(string filename, string contents) [Test] public void TestLogOutput() { + Utils.InconclusiveOnMono(); string filename = "test_simple.log"; SilentErrorHandler sh = new(); ILogger log = CreateLogger(filename, new FileAppender.ExclusiveLock(), sh); @@ -1421,6 +1420,7 @@ public void TestExclusiveLockFails() [Test] public void TestExclusiveLockRecovers() { + Utils.InconclusiveOnMono(); string filename = "test_exclusive_lock_recovers.log"; FileStream fs = new(filename, FileMode.Create, FileAccess.Write, FileShare.None); @@ -1444,10 +1444,7 @@ public void TestExclusiveLockRecovers() [Test] public void TestExclusiveLockLocks() { - if (isMono) - { - Assert.Inconclusive("mono has a different behaviour"); - } + Utils.InconclusiveOnMono(); string filename = "test_exclusive_lock_locks.log"; bool locked = false; @@ -1484,6 +1481,7 @@ public void TestExclusiveLockLocks() [Test] public void TestMinimalLockFails() { + Utils.InconclusiveOnMono(); string filename = "test_minimal_lock_fails.log"; FileStream fs = new(filename, FileMode.Create, FileAccess.Write, FileShare.None); @@ -1507,6 +1505,7 @@ public void TestMinimalLockFails() [Test] public void TestMinimalLockRecovers() { + Utils.InconclusiveOnMono(); string filename = "test_minimal_lock_recovers.log"; FileStream fs = new(filename, FileMode.Create, FileAccess.Write, FileShare.None); @@ -1530,6 +1529,7 @@ public void TestMinimalLockRecovers() [Test] public void TestMinimalLockUnlocks() { + Utils.InconclusiveOnMono(); string filename = "test_minimal_lock_unlocks.log"; bool locked; @@ -1558,6 +1558,7 @@ public void TestMinimalLockUnlocks() [Test] public void TestInterProcessLockFails() { + Utils.InconclusiveOnMono(); string filename = "test_interprocess_lock_fails.log"; FileStream fs = new(filename, FileMode.Create, FileAccess.Write, FileShare.None); @@ -1581,6 +1582,7 @@ public void TestInterProcessLockFails() [Test] public void TestInterProcessLockRecovers() { + Utils.InconclusiveOnMono(); string filename = "test_interprocess_lock_recovers.log"; FileStream fs = new(filename, FileMode.Create, FileAccess.Write, FileShare.None); @@ -1604,6 +1606,7 @@ public void TestInterProcessLockRecovers() [Test] public void TestInterProcessLockUnlocks() { + Utils.InconclusiveOnMono(); string filename = "test_interprocess_lock_unlocks.log"; bool locked; @@ -1632,6 +1635,7 @@ public void TestInterProcessLockUnlocks() [Test] public void TestInterProcessLockRoll() { + Utils.InconclusiveOnMono(); const string filename = "test_interprocess_lock_roll.log"; SilentErrorHandler sh = new(); diff --git a/src/log4net.Tests/Appender/SmtpPickupDirAppenderTest.cs b/src/log4net.Tests/Appender/SmtpPickupDirAppenderTest.cs index 05a1e4c6..48fdcd74 100644 --- a/src/log4net.Tests/Appender/SmtpPickupDirAppenderTest.cs +++ b/src/log4net.Tests/Appender/SmtpPickupDirAppenderTest.cs @@ -170,6 +170,7 @@ private static void DestroyLogger() [Test] public void TestOutputContainsSentDate() { + Utils.InconclusiveOnMono(); SilentErrorHandler sh = new SilentErrorHandler(); SmtpPickupDirAppender appender = CreateSmtpPickupDirAppender(sh); ILogger log = CreateLogger(appender); @@ -203,6 +204,7 @@ public void TestOutputContainsSentDate() [Test] public void TestConfigurableFileExtension() { + Utils.InconclusiveOnMono(); const string fileExtension = "eml"; SilentErrorHandler sh = new SilentErrorHandler(); SmtpPickupDirAppender appender = CreateSmtpPickupDirAppender(sh); @@ -226,6 +228,7 @@ public void TestConfigurableFileExtension() [Test] public void TestDefaultFileNameIsAGuid() { + Utils.InconclusiveOnMono(); SilentErrorHandler sh = new SilentErrorHandler(); SmtpPickupDirAppender appender = CreateSmtpPickupDirAppender(sh); ILogger log = CreateLogger(appender); diff --git a/src/log4net.Tests/Core/LoggingEventTest.cs b/src/log4net.Tests/Core/LoggingEventTest.cs index d5f535b0..df6daddc 100644 --- a/src/log4net.Tests/Core/LoggingEventTest.cs +++ b/src/log4net.Tests/Core/LoggingEventTest.cs @@ -39,6 +39,7 @@ private static readonly DateTime localTime [Test] public void SerializeDeserialize_BinaryFormatter() { + Utils.InconclusiveOnMono(); var timestamp = localTime.ToUniversalTime(); var ev = new LoggingEvent(new LoggingEventData { @@ -87,6 +88,7 @@ public void SerializeDeserialize_BinaryFormatter() [Test] public void DeserializeV2() { + Utils.InconclusiveOnMono(); const string datPath = @"..\..\..\..\integration-testing\log4net2-SerializeEvent\SerializeV2Event.dat"; using var stream = File.OpenRead(datPath); var formatter = new BinaryFormatter(); diff --git a/src/log4net.Tests/Utils.cs b/src/log4net.Tests/Utils.cs index 1caee5af..4d7a8eac 100644 --- a/src/log4net.Tests/Utils.cs +++ b/src/log4net.Tests/Utils.cs @@ -17,15 +17,40 @@ // #endregion +using System; +using NUnit.Framework; + namespace log4net.Tests { /// - /// Summary description for Class1. + /// Utilities for testing /// public static class Utils { + /// + /// Is the mono runtime used + /// + internal static bool IsMono { get; } = Type.GetType("Mono.Runtime") is not null; + + /// + /// Skips the current test when run under mono + /// + internal static void InconclusiveOnMono() + { + if (IsMono) + { + Assert.Inconclusive("mono has a different behaviour"); + } + } + + /// + /// Sample property key + /// internal const string PROPERTY_KEY = "prop1"; + /// + /// Remove the from alle log4net contexts + /// internal static void RemovePropertyFromAllContexts() { GlobalContext.Properties.Remove(PROPERTY_KEY);