Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented proper support of netstandard2.0 #63

Merged
merged 6 commits into from Sep 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -242,3 +242,4 @@ build-tools
buildreports
vs_buildtools.exe
dotnetfx35.exe
*.exe
7 changes: 7 additions & 0 deletions BUILDING.md
Expand Up @@ -18,6 +18,13 @@ Options:
- on Win10+, this can only be installed via Add/Remove Windows Components
- on other platforms, see https://dotnet.microsoft.com/download/dotnet-framework/net35-sp1
- Building against .net 2/3.5, especially Client Profile, is not supported on Mono
- Log4Net supports some older, out-of-support .net SDKs, particularly
dotnet core 1.1 and .net framework client profiles for 3.5 and 4.0.
There are helper powershell scripts in the root of this
repository to assist with obtaining and installing these
SDKs from Microsoft servers. Please see:
- [install-dotnet-core-sdk-1.1.ps1](install-dotnet-core-sdk-1.1.ps1)
- [install-net-framework-sdk-3.5.ps1](install-net-framework-sdk-3.5.ps1)
- Binaries can be built with a Visual Studio or Rider installation
- Binaries, packages and a release zip can be built via commandline
- Ensure that you have a reasonably modern NodeJS installed (at least version 8+)
Expand Down
17 changes: 16 additions & 1 deletion README.md
Expand Up @@ -27,5 +27,20 @@ tracker is no longer accepting new issues but is available at
https://issues.apache.org/jira/browse/LOG4NET for access to
previous issues.

Developing
==========

log4net targets a wide array of .net platforms, including some
which are out of support from Microsoft, making it difficult to
install relevant SDKs and build for those targets. In particular,
older Client Profile .NET Framework targets and dotnet core 1.1
may be installed by using the bundled helper scripts:

- [install-net-framework-sdk-3.5.ps1]()
- [install-dotnet-core-sdk-1.1.ps1]()

These scripts download the relevant installers from Microsoft servers,
but you run them at your own risk.

Please see [CONTRIBUTING.md](CONTRIBUTING.md) and
[BUILDING.md](BUILDING.md)
[BUILDING.md](BUILDING.md)
7 changes: 7 additions & 0 deletions install-dotnet-core-sdk-1.1.ps1
@@ -0,0 +1,7 @@
$installer="dotnet-dev-win-x64.1.1.14.exe"
Write-Host "Downloading $installer"
Invoke-WebRequest -Uri "https://download.visualstudio.microsoft.com/download/pr/c6b9a396-5e7a-4b91-86f6-f9e8df3bf1dd/6d61addfd6069e404981bede03f8f4f9/$installer" -OutFile $installer
Write-Host "Running $installer"
Start-Process -FilePath $installer -ArgumentList "/wait","/passive" -Wait
Write-Host "dotnet core sdk 1.1 installed"

File renamed without changes.
4 changes: 2 additions & 2 deletions local-tasks/zip.js
@@ -1,7 +1,7 @@
const
gulp = requireModule("gulp"),
promisify = requireModule("promisify-stream"),
readNuspecVersion = requireModule("read-nuspec-version"),
readCsProjVersion = requireModule("read-csproj-version"),
target = "build/artifacts",
zip = require("gulp-zip");

Expand Down Expand Up @@ -38,5 +38,5 @@ gulp.task("zip-source", async () => {
});

function readVersion() {
return readNuspecVersion("log4net.nuspec");
return readCsProjVersion("src/log4net/log4net.csproj");
}
127 changes: 0 additions & 127 deletions log4net.nuspec

This file was deleted.

12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions package.json
Expand Up @@ -5,13 +5,12 @@
"scripts": {
"test": "cross-env NUNIT_PROCESS=Single MAX_CONCURRENCY=1 run-s clean-build \"zarro test-dotnet\"",
"clean-build": "rimraf build",
"build": "run-s \"zarro build\"",
"build-release": "cross-env BUILD_CONFIGURATION=Release run-s \"zarro build\"",
"build": "run-s clean-build \"zarro build\"",
"build-release": "cross-env BUILD_CONFIGURATION=Release run-s clean-build \"zarro build\"",
"build-site": "run-s \"zarro build-site\"",
"pack": "cross-env PACKAGE_TARGET_FOLDER=build/artifacts PACK_INCREMENT_VERSION=false run-s \"zarro pack\"",
"zip": "run-s \"zarro zip\"",
"dump-env": "node -e \"console.log(process.env);\"",
"release": "run-s clean-build build-release pack zip",
"release": "run-s build-release zip",
"zarro": "cross-env BUILD_INCLUDE=src/log4net.sln zarro"
},
"repository": {
Expand All @@ -29,7 +28,7 @@
"gulp-zip": "^5.0.1",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"which": "^2.0.2",
"zarro": "^1.76.0"
"zarro": "^1.77.0",
"which": "^2.0.2"
}
}
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