From 1dc9ca2b64460248bc77e25bc924fa51177b13d5 Mon Sep 17 00:00:00 2001
From: Jan Friedrich
Date: Fri, 6 Sep 2024 00:59:51 +0200
Subject: [PATCH] #175 Dropping support for legacy serialization
---
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 | 22 +++++++++++++++++++
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 ++++
19 files changed, 48 insertions(+), 22 deletions(-)
create mode 100644 src/log4net/Core/Serializable.cs
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..19cfaf2d
--- /dev/null
+++ b/src/log4net/Core/Serializable.cs
@@ -0,0 +1,22 @@
+#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;
+#endif
+
+namespace log4net.Core;
+#if !NET462_OR_GREATER
+///
+/// Empty Interface (as replacement for )
+///
+internal interface IEmptyInterface
+{ }
+
+///
+/// Empty Attribute (as replacement for )
+///
+internal sealed class EmptyAttribute : System.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
+