Skip to content

Commit

Permalink
remove obsolete #ifdefs #111
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeAndNil committed Mar 5, 2024
1 parent 2e5a79a commit a88c5a5
Show file tree
Hide file tree
Showing 105 changed files with 524 additions and 2,615 deletions.
19 changes: 1 addition & 18 deletions src/log4net/Appender/AdoNetAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,11 @@
//
#endregion

// SSCLI 1.0 has no support for ADO.NET
#if !SSCLI

using System;
using System.Collections;
#if !NETSTANDARD1_3
using System.Configuration;
#endif
using System.Data;
using System.IO;
#if NETSTANDARD1_3
using System.Reflection;
#endif

using log4net.Util;
using log4net.Layout;
Expand Down Expand Up @@ -683,7 +675,6 @@ protected virtual string ResolveConnectionString(out string connectionStringCont
return ConnectionString;
}

#if !NETSTANDARD1_3
if (!String.IsNullOrEmpty(ConnectionStringName))
{
ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[ConnectionStringName];
Expand All @@ -697,7 +688,6 @@ protected virtual string ResolveConnectionString(out string connectionStringCont
throw new LogException("Unable to find [" + ConnectionStringName + "] ConfigurationManager.ConnectionStrings item");
}
}
#endif

if (AppSettingsKey != null && AppSettingsKey.Length > 0)
{
Expand Down Expand Up @@ -733,12 +723,7 @@ protected virtual Type ResolveConnectionType()
{
try
{
#if NETSTANDARD1_3
// NETSTANDARD1_3 requires comma separated ConnectionType like `System.Data.SqlClient.SqlConnection, System.Data` to work properly.
return SystemInfo.GetTypeFromString((Assembly)null, ConnectionType, true, false);
#else
return SystemInfo.GetTypeFromString(ConnectionType, true, false);
#endif
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1179,6 +1164,4 @@ public virtual void FormatValue(IDbCommand command, LoggingEvent loggingEvent)

#endregion // Private Instance Fields
}
}

#endif // !SSCLI
}
5 changes: 0 additions & 5 deletions src/log4net/Appender/AnsiColorTerminalAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,6 @@ protected override void Append(log4net.Core.LoggingEvent loggingEvent)
}
}

#if NETCF_1_0
// Write to the output stream
Console.Write(loggingMessage);
#else
if (m_writeToErrorStream)
{
// Write to the error stream
Expand All @@ -353,7 +349,6 @@ protected override void Append(log4net.Core.LoggingEvent loggingEvent)
// Write to the output stream
Console.Write(loggingMessage);
}
#endif

}

Expand Down
5 changes: 1 addition & 4 deletions src/log4net/Appender/AppenderCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ namespace log4net.Appender
/// A strongly-typed collection of <see cref="IAppender"/> objects.
/// </summary>
/// <author>Nicko Cadell</author>
public class AppenderCollection : ICollection, IList, IEnumerable
#if !NETSTANDARD1_3
, ICloneable
#endif
public class AppenderCollection : ICollection, IList, IEnumerable, ICloneable
{
#region Interfaces
/// <summary>
Expand Down
22 changes: 0 additions & 22 deletions src/log4net/Appender/AppenderSkeleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,6 @@ public void DoAppend(LoggingEvent loggingEvent)
{
ErrorHandler.Error("Failed in DoAppend", ex);
}
#if !MONO && !NET_2_0 && !NETSTANDARD
// on .NET 2.0 (and higher) and Mono (all profiles),
// exceptions that do not derive from System.Exception will be
// wrapped in a RuntimeWrappedException by the runtime, and as
// such will be catched by the catch clause above
catch
{
// Catch handler for non System.Exception types
ErrorHandler.Error("Failed in DoAppend (unknown exception)");
}
#endif
finally
{
m_recursiveGuard = false;
Expand Down Expand Up @@ -428,17 +417,6 @@ public void DoAppend(LoggingEvent[] loggingEvents)
{
ErrorHandler.Error("Failed in Bulk DoAppend", ex);
}
#if !MONO && !NET_2_0 && !NETSTANDARD
// on .NET 2.0 (and higher) and Mono (all profiles),
// exceptions that do not derive from System.Exception will be
// wrapped in a RuntimeWrappedException by the runtime, and as
// such will be catched by the catch clause above
catch
{
// Catch handler for non System.Exception types
ErrorHandler.Error("Failed in Bulk DoAppend (unknown exception)");
}
#endif
finally
{
m_recursiveGuard = false;
Expand Down
22 changes: 8 additions & 14 deletions src/log4net/Appender/AspNetTraceAppender.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET_2_0
#if NET462_OR_GREATER
#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
Expand All @@ -18,10 +18,6 @@
//
#endregion

// .NET Compact Framework 1.0 has no support for ASP.NET
// SSCLI 1.0 has no support for ASP.NET
#if !NETCF && !SSCLI && !CLIENT_PROFILE

using System.Web;

using log4net.Layout;
Expand Down Expand Up @@ -54,7 +50,7 @@ namespace log4net.Appender
/// <author>Nicko Cadell</author>
/// <author>Gert Driesen</author>
/// <author>Ron Grabowski</author>
public class AspNetTraceAppender : AppenderSkeleton
public class AspNetTraceAppender : AppenderSkeleton
{
#region Public Instances Constructors

Expand Down Expand Up @@ -85,19 +81,19 @@ public AspNetTraceAppender()
/// (<see cref="TraceContext"/>).
/// </para>
/// </remarks>
protected override void Append(LoggingEvent loggingEvent)
protected override void Append(LoggingEvent loggingEvent)
{
// check if log4net is running in the context of an ASP.NET application
if (HttpContext.Current != null)
if (HttpContext.Current != null)
{
// check if tracing is enabled for the current context
if (HttpContext.Current.Trace.IsEnabled)
if (HttpContext.Current.Trace.IsEnabled)
{
if (loggingEvent.Level >= Level.Warn)
if (loggingEvent.Level >= Level.Warn)
{
HttpContext.Current.Trace.Warn(m_category.Format(loggingEvent), RenderLoggingEvent(loggingEvent));
}
else
else
{
HttpContext.Current.Trace.Write(m_category.Format(loggingEvent), RenderLoggingEvent(loggingEvent));
}
Expand Down Expand Up @@ -152,6 +148,4 @@ public PatternLayout Category
#endregion
}
}

#endif // !NETCF && !SSCLI
#endif // NET_2_0
#endif
24 changes: 1 addition & 23 deletions src/log4net/Appender/ColoredConsoleAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@
//
#endregion

// MONO 1.0 Beta mcs does not like #if !A && !B && !C syntax

#if !NETSTANDARD1_3 // netstandard doesn't support System.Security.Permissions
// .NET Compact Framework 1.0 has no support for Win32 Console API's
#if !NETCF
// .Mono 1.0 has no support for Win32 Console API's
#if !MONO
// SSCLI 1.0 has no support for Win32 Console API's
#if !SSCLI
// We don't want framework or platform specific code in the CLI version of log4net
#if !CLI_1_0

using System;
using System.Globalization;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -266,9 +254,7 @@ public void AddMapping(LevelColors mapping)
/// The format of the output will depend on the appender's layout.
/// </para>
/// </remarks>
#if NET_4_0 || MONO_4_0 || NETSTANDARD
[System.Security.SecuritySafeCritical]
#endif
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, UnmanagedCode = true)]
protected override void Append(log4net.Core.LoggingEvent loggingEvent)
{
Expand Down Expand Up @@ -435,9 +421,7 @@ protected override bool RequiresLayout
/// Initialize the level to color mappings set on this appender.
/// </para>
/// </remarks>
#if NET_4_0 || MONO_4_0 || NETSTANDARD
[System.Security.SecuritySafeCritical]
#endif
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, UnmanagedCode = true)]
public override void ActivateOptions()
{
Expand Down Expand Up @@ -659,10 +643,4 @@ internal ushort CombinedColor

#endregion // LevelColors LevelMapping Entry
}
}

#endif // !CLI_1_0
#endif // !SSCLI
#endif // !MONO
#endif // !NETCF
#endif // !NETSTANDARD1_3
}
5 changes: 0 additions & 5 deletions src/log4net/Appender/ConsoleAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ public virtual string Target
/// </remarks>
protected override void Append(LoggingEvent loggingEvent)
{
#if NETCF_1_0
// Write to the output stream
Console.Write(RenderLoggingEvent(loggingEvent));
#else
if (m_writeToErrorStream)
{
// Write to the error stream
Expand All @@ -165,7 +161,6 @@ protected override void Append(LoggingEvent loggingEvent)
// Write to the output stream
Console.Write(RenderLoggingEvent(loggingEvent));
}
#endif
}

/// <summary>
Expand Down
22 changes: 1 addition & 21 deletions src/log4net/Appender/DebugAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public DebugAppender(ILayout layout)

#region Public Instance Properties

#if !NETSTANDARD1_3 // System.Diagnostics.Debug has no Flush() in netstandard1.3
/// <summary>
/// Gets or sets a value that indicates whether the appender will
/// flush at the end of each write.
Expand All @@ -100,7 +99,6 @@ public bool ImmediateFlush
get { return m_immediateFlush; }
set { m_immediateFlush = value; }
}
#endif // !NETSTANDARD1_3

/// <summary>
/// Formats the category parameter sent to the Debug method.
Expand All @@ -121,7 +119,6 @@ public PatternLayout Category

#endregion Public Instance Properties

#if !NETSTANDARD1_3
/// <summary>
/// Flushes any buffered log data.
/// </summary>
Expand All @@ -137,21 +134,9 @@ public override bool Flush(int millisecondsTimeout)

return true;
}
#endif

#region Override implementation of AppenderSkeleton

#if NETSTANDARD1_3
/// <summary>
/// Writes the logging event to the <see cref="System.Diagnostics.Debug"/> system.
/// </summary>
/// <param name="loggingEvent">The event to log.</param>
/// <remarks>
/// <para>
/// Writes the logging event to the <see cref="System.Diagnostics.Debug"/> system.
/// </para>
/// </remarks>
#else
/// <summary>
/// Writes the logging event to the <see cref="System.Diagnostics.Debug"/> system.
/// </summary>
Expand All @@ -163,7 +148,6 @@ public override bool Flush(int millisecondsTimeout)
/// is called.
/// </para>
/// </remarks>
#endif
protected override void Append(LoggingEvent loggingEvent)
{
//
Expand All @@ -185,15 +169,13 @@ protected override void Append(LoggingEvent loggingEvent)
System.Diagnostics.Debug.Write(RenderLoggingEvent(loggingEvent), category);
}
}
#if !NETSTANDARD1_3
//
// Flush the Debug system if needed
//
if (m_immediateFlush)
{
System.Diagnostics.Debug.Flush();
}
#endif
}

/// <summary>
Expand All @@ -214,7 +196,6 @@ protected override bool RequiresLayout

#region Private Instance Fields

#if !NETSTANDARD1_3
/// <summary>
/// Immediate flush means that the underlying writer or output stream
/// will be flushed at the end of each append operation.
Expand All @@ -231,7 +212,6 @@ protected override bool RequiresLayout
/// The default value is <c>true</c>.</para>
/// </remarks>
private bool m_immediateFlush = true;
#endif

/// <summary>
/// Defaults to a <see cref="Layout.PatternLayout"/> with %logger as the pattern.
Expand All @@ -240,4 +220,4 @@ protected override bool RequiresLayout

#endregion Private Instance Fields
}
}
}
19 changes: 2 additions & 17 deletions src/log4net/Appender/EventLogAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@
//
#endregion

// MONO 1.0 Beta mcs does not like #if !A && !B && !C syntax

// netstandard doesn't support EventLog
#if NET_2_0
// .NET Compact Framework 1.0 has no support for EventLog
#if !NETCF
// SSCLI 1.0 has no support for EventLog
#if !SSCLI

#if NET462_OR_GREATER
using System;
using System.Diagnostics;
using System.Globalization;

using log4net.Util;
using log4net.Layout;
Expand Down Expand Up @@ -356,13 +348,9 @@ public override void ActivateOptions()
/// </remarks>
private static void CreateEventSource(string source, string logName, string machineName)
{
#if NET_2_0
EventSourceCreationData eventSourceCreationData = new EventSourceCreationData(source, logName);
eventSourceCreationData.MachineName = machineName;
EventLog.CreateEventSource(eventSourceCreationData);
#else
EventLog.CreateEventSource(source, logName, machineName);
#endif
}

#region Override implementation of AppenderSkeleton
Expand Down Expand Up @@ -689,7 +677,4 @@ private static int GetMaxEventLogMessageSize()
#endregion Private Static Fields
}
}

#endif // !SSCLI
#endif // !NETCF
#endif // NET_2_0
#endif // NET462_OR_GREATER
Loading

0 comments on commit a88c5a5

Please sign in to comment.