Skip to content

Commit

Permalink
Added support for .NET Standard 2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmic86 committed Sep 17, 2019
1 parent c04a774 commit 962cb46
Show file tree
Hide file tree
Showing 34 changed files with 525 additions and 181 deletions.
3 changes: 3 additions & 0 deletions netstandard_2_0/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"projects": [ "log4net", "log4net.tests" ]
}
37 changes: 37 additions & 0 deletions netstandard_2_0/log4net.netstandard_2_0.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29215.179
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4BB38D1C-1862-432B-881C-925714F7F997}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
nuget.config = nuget.config
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "log4net", "log4net\log4net.csproj", "{00764202-B361-4BC8-A1B9-01D87F9D2D51}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "log4net.tests", "log4net.tests\log4net.tests.csproj", "{6A78D53B-C864-4316-AA00-F2EBFE975223}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00764202-B361-4BC8-A1B9-01D87F9D2D51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00764202-B361-4BC8-A1B9-01D87F9D2D51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00764202-B361-4BC8-A1B9-01D87F9D2D51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00764202-B361-4BC8-A1B9-01D87F9D2D51}.Release|Any CPU.Build.0 = Release|Any CPU
{6A78D53B-C864-4316-AA00-F2EBFE975223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A78D53B-C864-4316-AA00-F2EBFE975223}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A78D53B-C864-4316-AA00-F2EBFE975223}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A78D53B-C864-4316-AA00-F2EBFE975223}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D067DD82-BB0E-4938-A085-540D3E9FF1F4}
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions netstandard_2_0/log4net.tests/ApplicationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

using System;

namespace log4net.Tests
{
public class ApplicationException : Exception
{
}
}
38 changes: 38 additions & 0 deletions netstandard_2_0/log4net.tests/CompatibilityExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

using System;
using System.IO;
using System.Reflection;
using System.Threading;

namespace log4net
{
internal static class CompatibilityExtensions
{
public static void Close(this Mutex mutex) => mutex.Dispose();
public static void Close(this Stream stream) => stream.Dispose();
public static void Close(this StreamReader streamReader) => streamReader.Dispose();

public static ConstructorInfo GetConstructor(this Type type, BindingFlags bindingAttr, object binder, Type[] types, object[] modifiers)
{
return type.GetConstructor(types);
}
}
}
85 changes: 85 additions & 0 deletions netstandard_2_0/log4net.tests/ExpectedExceptionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

// https://github.com/nunit/nunit-csharp-samples/blob/master/ExpectedExceptionExample/ExpectedExceptionAttribute.cs

using System;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands;

namespace NUnit.Framework
{
/// <summary>
/// A simple ExpectedExceptionAttribute
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class ExpectedExceptionAttribute : NUnitAttribute, IWrapTestMethod
{
private readonly Type _expectedExceptionType;

public ExpectedExceptionAttribute(Type type)
{
_expectedExceptionType = type;
}

public TestCommand Wrap(TestCommand command)
{
return new ExpectedExceptionCommand(command, _expectedExceptionType);
}

private class ExpectedExceptionCommand : DelegatingTestCommand
{
private readonly Type _expectedType;

public ExpectedExceptionCommand(TestCommand innerCommand, Type expectedType)
: base(innerCommand)
{
_expectedType = expectedType;
}

public override TestResult Execute(TestExecutionContext context)
{
Type caughtType = null;

try
{
innerCommand.Execute(context);
}
catch (Exception ex)
{
if (ex is NUnitException)
ex = ex.InnerException;
caughtType = ex.GetType();
}

if (caughtType == _expectedType)
context.CurrentResult.SetResult(ResultState.Success);
else if (caughtType != null)
context.CurrentResult.SetResult(ResultState.Failure,
string.Format("Expected {0} but got {1}", _expectedType.Name, caughtType.Name));
else
context.CurrentResult.SetResult(ResultState.Failure,
string.Format("Expected {0} but no exception was thrown", _expectedType.Name));

return context.CurrentResult;
}
}
}
}
32 changes: 32 additions & 0 deletions netstandard_2_0/log4net.tests/log4net.tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>2.0.9</VersionPrefix>
<TargetFramework>netcoreapp2.0</TargetFramework>
<DefineConstants>$(DefineConstants);NETSTANDARD2_0</DefineConstants>
<AssemblyName>log4net.tests</AssemblyName>
<PackageId>log4net.tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8</AssetTargetFallback>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\tests\src\*.cs;..\..\tests\src\Appender\AppenderCollectionTest.cs;..\..\tests\src\Appender\BufferingAppenderTest.cs;..\..\tests\src\Appender\CountingAppender.cs;..\..\tests\src\Appender\MemoryAppenderTest.cs;..\..\tests\src\Appender\RollingFileAppenderTest.cs;..\..\tests\src\Appender\SmtpPickupDirAppenderTest.cs;..\..\tests\src\Appender\StringAppender.cs;..\..\tests\src\Appender\TraceAppenderTest.cs;..\..\tests\src\Context\LogicalThreadContextTest.cs;..\..\tests\src\Context\ThreadContextTest.cs;..\..\tests\src\Core\**\*.cs;..\..\tests\src\DateFormatter\**\*.cs;..\..\tests\src\Hierarchy\**\*.cs;..\..\tests\src\Layout\**\*.cs;..\..\tests\src\LoggerRepository\**\*.cs;..\..\tests\src\Util\CyclicBufferTest.cs;..\..\tests\src\Util\LogLogTest.cs;..\..\tests\src\Util\PatternConverterTest.cs;..\..\tests\src\Util\RandomStringPatternConverterTest.cs;..\..\tests\src\Util\SystemInfoTest.cs;..\..\tests\src\Util\TransformTest.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
<ProjectReference Include="..\log4net\log4net.csproj" />
<PackageReference Include="dotnet-test-nunit" Version="3.4.0-beta-2" />
<PackageReference Include="NUnit" Version="3.4.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
</ItemGroup>

</Project>
58 changes: 58 additions & 0 deletions netstandard_2_0/log4net/CompatibilityExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

#if NETSTANDARD1_3 || NETSTANDARD2_0

using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Threading;
using System.Xml;

namespace log4net
{
internal static class CompatibilityExtensions
{
public static void Close(this Mutex mutex) => mutex.Dispose();
public static void Close(this Socket socket) => socket.Dispose();
public static void Close(this Stream stream) => stream.Dispose();
public static void Close(this StreamWriter streamWriter) => streamWriter.Dispose();
public static void Close(this UdpClient client) => client.Dispose();
public static void Close(this WebResponse response) => response.Dispose();
public static void Close(this XmlWriter xmlWriter) => xmlWriter.Dispose();

#if NETSTANDARD1_3
public static Attribute[] GetCustomAttributes(this Type type, Type other, bool inherit) => type.GetTypeInfo().GetCustomAttributes(other, inherit).ToArray();
#else
public static object[] GetCustomAttributes(this Type type, Type other, bool inherit) => type.GetTypeInfo().GetCustomAttributes(other, inherit).ToArray();
#endif

public static bool IsAssignableFrom(this Type type, Type other) => type.GetTypeInfo().IsAssignableFrom(other.GetTypeInfo());
public static bool IsSubclassOf(this Type type, Type t) => type.GetTypeInfo().IsSubclassOf(t);

public static string ToLower(this string s, CultureInfo cultureInfo) => cultureInfo.TextInfo.ToLower(s);
public static string ToUpper(this string s, CultureInfo cultureInfo) => cultureInfo.TextInfo.ToUpper(s);
}
}

#endif
61 changes: 61 additions & 0 deletions netstandard_2_0/log4net/log4net.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Copyright>Copyright 2004-2017 The Apache Software Foundation.</Copyright>
<AssemblyTitle>Apache log4net for .NET Core</AssemblyTitle>
<VersionPrefix>2.0.9</VersionPrefix>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>log4net</AssemblyName>
<PackageId>log4net</PackageId>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);HAS_READERWRITERLOCKSLIM</DefineConstants>
<PublicSign>true</PublicSign>
<AssemblyOriginatorKeyFile>../../log4net.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<Compile Remove="..\..\src\Appender\AdoNetAppender.cs;..\..\src\Appender\AspNetTraceAppender.cs;..\..\src\Appender\ColoredConsoleAppender.cs;..\..\src\Appender\EventLogAppender.cs;..\..\src\Appender\NetSendAppender.cs;..\..\src\Appender\RemotingAppender.cs;..\..\src\Appender\SmtpAppender.cs;..\..\src\Config\DOMConfigurator.cs;..\..\src\Config\DOMConfiguratorAttribute.cs;..\..\src\Config\Log4NetConfigurationSectionHandler.cs;..\..\src\Layout\Pattern\AspNetCachePatternConverter.cs;..\..\src\Layout\Pattern\AspNetContextPatternConverter.cs;..\..\src\Layout\Pattern\AspNetPatternConverter.cs;..\..\src\Layout\Pattern\AspNetRequestPatternConverter.cs;..\..\src\Layout\Pattern\AspNetSessionPatternConverter.cs;..\..\src\Layout\Pattern\StackTraceDetailPatternConverter.cs;..\..\src\Layout\Pattern\StackTracePatternConverter.cs;..\..\src\Plugin\RemoteLoggingServerPlugin.cs;..\..\src\Util\PatternStringConverters\AppSettingPatternConverter.cs;..\..\src\Util\PatternStringConverters\EnvironmentFolderPathPatternConverter.cs;..\..\src\Util\NativeError.cs;..\..\src\Util\WindowsSecurityContext.cs" />
<Compile Include="..\..\src\**\*.cs" Exclude="..\..\src\Appender\AdoNetAppender.cs;..\..\src\Appender\AspNetTraceAppender.cs;..\..\src\Appender\ColoredConsoleAppender.cs;..\..\src\Appender\EventLogAppender.cs;..\..\src\Appender\NetSendAppender.cs;..\..\src\Appender\RemotingAppender.cs;..\..\src\Appender\SmtpAppender.cs;..\..\src\Config\DOMConfigurator.cs;..\..\src\Config\DOMConfiguratorAttribute.cs;..\..\src\Config\Log4NetConfigurationSectionHandler.cs;..\..\src\Layout\Pattern\AspNetCachePatternConverter.cs;..\..\src\Layout\Pattern\AspNetContextPatternConverter.cs;..\..\src\Layout\Pattern\AspNetPatternConverter.cs;..\..\src\Layout\Pattern\AspNetRequestPatternConverter.cs;..\..\src\Layout\Pattern\AspNetSessionPatternConverter.cs;..\..\src\Layout\Pattern\StackTraceDetailPatternConverter.cs;..\..\src\Layout\Pattern\StackTracePatternConverter.cs;..\..\src\Plugin\RemoteLoggingServerPlugin.cs;..\..\src\Util\PatternStringConverters\AppSettingPatternConverter.cs;..\..\src\Util\PatternStringConverters\EnvironmentFolderPathPatternConverter.cs;..\..\src\Util\NativeError.cs;..\..\src\Util\WindowsSecurityContext.cs;bin\**;obj\**;**\*.xproj;packages\**" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.AppContext" Version="4.1.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.0.1" />
<PackageReference Include="System.Console" Version="4.0.0" />
<PackageReference Include="System.Diagnostics.Debug" Version="4.0.11" />
<PackageReference Include="System.Diagnostics.Process" Version="4.1.0" />
<PackageReference Include="System.Diagnostics.StackTrace" Version="4.0.1" />
<PackageReference Include="System.Diagnostics.TraceSource" Version="4.0.0" />
<PackageReference Include="System.IO.FileSystem" Version="4.0.1" />
<PackageReference Include="System.IO.FileSystem.Watcher" Version="4.0.0" />
<PackageReference Include="System.Linq" Version="4.1.0" />
<PackageReference Include="System.Net.NameResolution" Version="4.0.0" />
<PackageReference Include="System.Net.Requests" Version="4.0.11" />
<PackageReference Include="System.Net.Sockets" Version="4.1.0" />
<PackageReference Include="System.Reflection" Version="4.3.0" />
<PackageReference Include="System.Reflection.Extensions" Version="4.0.1" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.1.0" />
<PackageReference Include="System.Runtime.Extensions" Version="4.1.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.1.0" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.0.0" />
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.1.0" />
<PackageReference Include="System.Threading" Version="4.0.11" />
<PackageReference Include="System.Threading.Thread" Version="4.0.0" />
<PackageReference Include="System.Threading.Timer" Version="4.0.1" />
<PackageReference Include="System.Xml.ReaderWriter" Version="4.0.11" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.0.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Appender/AppenderCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace log4net.Appender
/// </summary>
/// <author>Nicko Cadell</author>
public class AppenderCollection : ICollection, IList, IEnumerable
#if !NETSTANDARD1_3
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
, ICloneable
#endif
{
Expand Down
4 changes: 2 additions & 2 deletions src/Appender/AppenderSkeleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void DoAppend(LoggingEvent loggingEvent)
{
ErrorHandler.Error("Failed in DoAppend", ex);
}
#if !MONO && !NET_2_0 && !NETSTANDARD1_3
#if !MONO && !NET_2_0 && !NETSTANDARD1_3 && !NETSTANDARD2_0
// 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
Expand Down Expand Up @@ -428,7 +428,7 @@ public void DoAppend(LoggingEvent[] loggingEvents)
{
ErrorHandler.Error("Failed in Bulk DoAppend", ex);
}
#if !MONO && !NET_2_0 && !NETSTANDARD1_3
#if !MONO && !NET_2_0 && !NETSTANDARD1_3 && !NETSTANDARD2_0
// 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
Expand Down
6 changes: 3 additions & 3 deletions src/Appender/DebugAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public PatternLayout Category
get { return m_category; }
set { m_category = value; }
}

#endregion Public Instance Properties

#if !NETSTANDARD1_3
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
/// <summary>
/// Flushes any buffered log data.
/// </summary>
Expand Down Expand Up @@ -171,7 +171,7 @@ override protected void Append(LoggingEvent loggingEvent)
System.Diagnostics.Debug.Write(RenderLoggingEvent(loggingEvent), category);
}
}
#if !NETSTANDARD1_3
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
//
// Flush the Debug system if needed
//
Expand Down
Loading

0 comments on commit 962cb46

Please sign in to comment.