Skip to content

Commit

Permalink
Implemented proper support of netstandard2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsar Nikolay committed Sep 2, 2020
1 parent 8178e51 commit c5492f3
Show file tree
Hide file tree
Showing 89 changed files with 419 additions and 29,602 deletions.
127 changes: 0 additions & 127 deletions log4net.nuspec

This file was deleted.

27 changes: 27 additions & 0 deletions src/log4net.Tests/Appender/AdoNetAppenderTest.cs
Expand Up @@ -21,10 +21,15 @@

using System;
using System.Data;
#if NETSTANDARD1_3
using System.Reflection;
#endif
using System.Xml;
using log4net.Appender;
using log4net.Config;
#if !NETSTANDARD1_3
using log4net.Core;
#endif
using log4net.Layout;
using log4net.Repository;
using log4net.Tests.Appender.AdoNet;
Expand All @@ -43,13 +48,18 @@ public void NoBufferingTest()

AdoNetAppender adoNetAppender = new AdoNetAppender();
adoNetAppender.BufferSize = -1;
#if NETSTANDARD1_3
adoNetAppender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName;
#else
adoNetAppender.ConnectionType = "log4net.Tests.Appender.AdoNet.Log4NetConnection";
#endif
adoNetAppender.ActivateOptions();

BasicConfigurator.Configure(rep, adoNetAppender);

ILog log = LogManager.GetLogger(rep.Name, "NoBufferingTest");
log.Debug("Message");
Assert.NotNull(Log4NetCommand.MostRecentInstance);
Assert.AreEqual(1, Log4NetCommand.MostRecentInstance.ExecuteNonQueryCount);
}

Expand All @@ -62,7 +72,11 @@ public void BufferingTest()

AdoNetAppender adoNetAppender = new AdoNetAppender();
adoNetAppender.BufferSize = bufferSize;
#if NETSTANDARD1_3
adoNetAppender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName;
#else
adoNetAppender.ConnectionType = "log4net.Tests.Appender.AdoNet.Log4NetConnection";
#endif
adoNetAppender.ActivateOptions();

BasicConfigurator.Configure(rep, adoNetAppender);
Expand All @@ -74,9 +88,11 @@ public void BufferingTest()
Assert.IsNull(Log4NetCommand.MostRecentInstance);
}
log.Debug("Message");
Assert.NotNull(Log4NetCommand.MostRecentInstance);
Assert.AreEqual(bufferSize+1, Log4NetCommand.MostRecentInstance.ExecuteNonQueryCount);
}

#if !NETSTANDARD1_3
[Test]
public void WebsiteExample()
{
Expand Down Expand Up @@ -147,6 +163,7 @@ public void WebsiteExample()

IDbCommand command = Log4NetCommand.MostRecentInstance;

Assert.NotNull(command);
Assert.AreEqual(
"INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)",
command.CommandText);
Expand Down Expand Up @@ -240,6 +257,7 @@ public void BufferingWebsiteExample()

IDbCommand command = Log4NetCommand.MostRecentInstance;

Assert.NotNull(command);
Assert.AreEqual(
"INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)",
command.CommandText);
Expand All @@ -258,6 +276,7 @@ public void BufferingWebsiteExample()
param = (IDbDataParameter)command.Parameters["@exception"];
Assert.IsEmpty((string)param.Value);
}
#endif

[Test]
public void NullPropertyXmlConfig()
Expand Down Expand Up @@ -293,6 +312,8 @@ public void NullPropertyXmlConfig()

log.Debug("Message");
IDbCommand command = Log4NetCommand.MostRecentInstance;
Assert.NotNull(command);

IDbDataParameter param = (IDbDataParameter)command.Parameters["@productId"];
Assert.AreNotEqual(SystemInfo.NullText, param.Value);
Assert.AreEqual(DBNull.Value, param.Value);
Expand All @@ -310,7 +331,11 @@ public void NullPropertyProgmaticConfig()
productIdParam.Layout = rawPropertyLayout;

AdoNetAppender appender = new AdoNetAppender();
#if NETSTANDARD1_3
appender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName;
#else
appender.ConnectionType = typeof(Log4NetConnection).FullName;
#endif
appender.BufferSize = -1;
appender.CommandText = "INSERT INTO Log ([productId]) VALUES (@productId)";
appender.AddParameter(productIdParam);
Expand All @@ -322,6 +347,8 @@ public void NullPropertyProgmaticConfig()

log.Debug("Message");
IDbCommand command = Log4NetCommand.MostRecentInstance;
Assert.NotNull(command);

IDbDataParameter param = (IDbDataParameter)command.Parameters["@productId"];
Assert.AreNotEqual(SystemInfo.NullText, param.Value);
Assert.AreEqual(DBNull.Value, param.Value);
Expand Down
6 changes: 4 additions & 2 deletions src/log4net.Tests/Appender/DebugAppenderTest.cs
Expand Up @@ -18,6 +18,8 @@
*
*/

#if NET_2_0

using System;
using System.Diagnostics;
using log4net.Appender;
Expand Down Expand Up @@ -113,7 +115,6 @@ public void DefaultCategoryTest()
Debug.Listeners.Remove(categoryTraceListener);
}

#if !NETSTANDARD1_3 // "LocationInfo can't get method names on NETSTANDARD1_3 due to unavailable stack frame APIs"
[Test]
public void MethodNameCategoryTest()
{
Expand All @@ -140,7 +141,6 @@ public void MethodNameCategoryTest()

Debug.Listeners.Remove(categoryTraceListener);
}
#endif

private class TestErrorHandler : IErrorHandler
{
Expand Down Expand Up @@ -171,3 +171,5 @@ public void Error(string message)
}
}
}

#endif
5 changes: 5 additions & 0 deletions src/log4net.Tests/Appender/EventLogAppenderTest.cs
Expand Up @@ -17,6 +17,9 @@
//
#endregion

// netstandard doesn't support EventLog
#if NET_2_0

using System.Diagnostics;

using log4net.Appender;
Expand Down Expand Up @@ -98,3 +101,5 @@ private static EventLogEntryType GetEntryType(EventLogAppender appender, Level l

}
}

#endif // NET_2_0
5 changes: 1 addition & 4 deletions src/log4net.Tests/Appender/EventRaisingAppender.cs
Expand Up @@ -20,11 +20,8 @@
*/

#if !NET_2_0 && !MONO_2_0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace log4net.Tests.Appender
{
Expand Down
4 changes: 1 addition & 3 deletions src/log4net.Tests/Appender/MemoryAppenderTest.cs
Expand Up @@ -19,16 +19,14 @@
*
*/

#if NET_4_0 || MONO_3_5 || MONO_4_0
#if NET_4_0 || MONO_3_5 || MONO_4_0 || NETSTANDARD

using System;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using log4net;
using log4net.Appender;
using log4net.Config;
using log4net.Core;
using log4net.Layout;
using log4net.Repository;

Expand Down
8 changes: 1 addition & 7 deletions src/log4net.Tests/Appender/RecursiveLoggingTest.cs
Expand Up @@ -21,16 +21,10 @@

#if !NET_2_0 && !MONO_2_0
using System;
using System.Data;
using System.Xml;
using log4net.Appender;
using System.Globalization;
using log4net.Config;
using log4net.Core;
using log4net.Layout;
using log4net.Repository;
using log4net.Util;
using NUnit.Framework;
using System.Globalization;

namespace log4net.Tests.Appender
{
Expand Down
9 changes: 7 additions & 2 deletions src/log4net.Tests/Appender/RemotingAppenderTest.cs
Expand Up @@ -17,6 +17,9 @@
//
#endregion

// .NET Compact Framework 1.0 && netstandard has no support for System.Runtime.Remoting
#if NET_2_0

using System;
using System.Collections;
using System.Reflection;
Expand Down Expand Up @@ -283,7 +286,7 @@ public void TearDown()
/// <summary>
/// Close down remoting infrastructure
/// </summary>
[TestFixtureTearDown]
[OneTimeTearDown]
public void UnregisterRemotingServerChannel() {
if (m_remotingChannel != null) {
((TcpChannel) m_remotingChannel).StopListening(null);
Expand Down Expand Up @@ -448,4 +451,6 @@ public void Test()
}
}
}
}
}

#endif // NET_2_0

0 comments on commit c5492f3

Please sign in to comment.