Skip to content

Commit

Permalink
Drop support ASP.NET Core 1
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed Aug 28, 2021
1 parent 2162208 commit 31cdd5b
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 80 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ targets and layout-renderes specific to ASP.NET (Core), MVC and IIS.
- [Getting started for ASP.NET Core 3](https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-3)
- [Getting started for ASP.NET Core 2](https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-2)
- [Getting started for .NET Core 2 Console application](https://github.com/NLog/NLog/wiki/Getting-started-with-.NET-Core-2---Console-application)
- [Getting started for ASP.NET Core 1 (csproj - vs2017)](https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-(csproj---vs2017))
- [How to use structured logging](https://github.com/NLog/NLog/wiki/How-to-use-structured-logging)

### Config
Expand All @@ -41,16 +40,15 @@ targets and layout-renderes specific to ASP.NET (Core), MVC and IIS.
For updates and releases, check [CHANGELOG.MD](CHANGELOG.MD) or [Releases](https://github.com/NLog/NLog.Web/releases)

## ASP.NET Core
ASP.NET Core 1, 2, 3 and 5 are supported!
ASP.NET Core 2, 3 and 5 are supported!

Supported platforms:

- For ASP.NET Core 5, .NET 5
- For ASP.NET Core 3, .NET Core 3.0
- For ASP.NET Core 2, .NET Standard 2.0+ and .NET 4.6+
- For ASP.NET Core 1, .NET Standard 1.5+ and .NET 4.5.x

ℹ️ Missing the trace and debug logs in .NET Core 2? [Check your appsettings.json](https://github.com/NLog/NLog.Web/wiki/Missing-trace%5Cdebug-logs-in-ASP.NET-Core-2%3F)
ℹ️ Missing the trace and debug logs? [Check your appsettings.json](https://github.com/NLog/NLog.Web/wiki/Missing-trace%5Cdebug-logs-in-ASP.NET-Core-2%3F)

Use the NLog.Web.AspNetCore package

Expand Down
6 changes: 3 additions & 3 deletions src/NLog.Web.AspNetCore/AspNetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Reflection;
using NLog.Config;
using NLog.Web.DependencyInjection;
#if ASP_NET_CORE1 || ASP_NET_CORE2
#if ASP_NET_CORE2
using Microsoft.AspNetCore.Builder;
using IHostingEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#endif
Expand All @@ -25,7 +25,7 @@ namespace NLog.Web
/// </summary>
public static class AspNetExtensions
{
#if ASP_NET_CORE1 || ASP_NET_CORE2
#if ASP_NET_CORE2
/// <summary>
/// Enable NLog Web for ASP.NET Core.
/// </summary>
Expand All @@ -39,7 +39,7 @@ public static void AddNLogWeb(this IApplicationBuilder app)
}
#endif

#if ASP_NET_CORE1 || ASP_NET_CORE2
#if ASP_NET_CORE2
/// <summary>
/// Apply NLog configuration from XML config.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/NLog.Web.AspNetCore/Config/SetupBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
#if !ASP_NET_CORE1 && !ASP_NET_CORE2
#if !ASP_NET_CORE2
using System.IO;
using System.Linq;
#endif
Expand All @@ -14,7 +14,7 @@ namespace NLog.Web
/// </summary>
public static class SetupBuilderExtensions
{
#if !ASP_NET_CORE1 && !ASP_NET_CORE2
#if !ASP_NET_CORE2
/// <summary>
/// Loads NLog LoggingConfiguration from appsettings.json from the NLog-section
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Text;
#if ASP_NET_CORE1 || ASP_NET_CORE2
#if ASP_NET_CORE2
using Microsoft.AspNetCore.Hosting;
using IHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#endif
Expand Down
22 changes: 1 addition & 21 deletions src/NLog.Web.AspNetCore/NLog.Web.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<TargetFrameworks>netstandard1.5;net451;net461;netstandard2.0;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;netcoreapp3.0</TargetFrameworks>
<Product>NLog.Web.AspNetCore v$(VersionPrefix)</Product>
<Description>
NLog LoggerProvider for Microsoft.Extensions.Logging and ASP.NET Core platform. Adds helpers and layout renderers for websites and web applications.
Expand All @@ -11,7 +11,6 @@ Supported platforms:
- For ASP.NET Core 5, .NET 5
- For ASP.NET Core 3, .NET Core 3.0
- For ASP.NET Core 2, .NET Standard 2.0+ and .NET 4.6+
- For ASP.NET Core 1, .NET Standard 1.5+ and .NET 4.5.x
</Description>
<Authors>Julian Verdurmen</Authors>
<Company>NLog</Company>
Expand Down Expand Up @@ -49,22 +48,12 @@ See also https://github.com/NLog/NLog.Web/releases
<Target Name="DownloadMissingContent" BeforeTargets="GenerateNuspec">
<DownloadFile SourceUrl="https://nlog-project.org/N.png" DestinationFolder="$(MSBuildThisFileDirectory)" />
</Target>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Title>ASP.NET Core 1 integration for NLog - .NET Framework 4.5.1+</Title>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE1</DefineConstants>
<DebugType Condition=" '$(Configuration)' == 'Debug' ">Full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Title>ASP.NET Core 2 integration for NLog - .NET Framework 4.6+</Title>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE2</DefineConstants>
<DebugType Condition=" '$(Configuration)' == 'Debug' ">Full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.5' ">
<Title>ASP.NET Core 1 integration for NLog - .NET Standard 1.5</Title>
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE1</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<Title>ASP.NET Core 2 integration for NLog - .NET Standard 2</Title>
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE2</DefineConstants>
Expand All @@ -76,15 +65,6 @@ See also https://github.com/NLog/NLog.Web/releases
<ItemGroup>
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.5' or '$(TargetFramework)' == 'net451' ">
<PackageReference Include="Microsoft.AspNetCore.Http" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="1.1.2" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461' ">
<!-- Fixed to 2.1.0 as 2.1 is Long Term Supported (LTS) and works with vanilla .NET Core 2.1 SDK -->
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/Internal/HttpContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal static HttpResponse TryGetResponse(this HttpContext context)
}
#endif

#if ASP_NET_CORE1 || ASP_NET_CORE2
#if ASP_NET_CORE2
internal static string GetString(this ISession session, string key)
{
if (!session.TryGetValue(key, out var data))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Text;
#if ASP_NET_CORE
using System.IO;
#if ASP_NET_CORE1 || ASP_NET_CORE2
#if ASP_NET_CORE2
using Microsoft.AspNetCore.Hosting;
using IHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#endif
Expand Down
3 changes: 0 additions & 3 deletions src/Shared/LayoutRenderers/AspNetRequestPostedBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ private static Stream EnableRewind(HttpRequest httpRequest, int bufferThreshold)
#if ASP_NET_CORE2 || ASP_NET_CORE3
Microsoft.AspNetCore.Http.HttpRequestRewindExtensions.EnableBuffering(httpRequest, bufferThreshold);
return httpRequest.Body;
#elif ASP_NET_CORE1
Microsoft.AspNetCore.Http.Internal.BufferingHelper.EnableRewind(httpRequest, bufferThreshold);
return httpRequest.Body;
#else
return null;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using NLog.LayoutRenderers;
#if ASP_NET_CORE
using Microsoft.AspNetCore.Hosting;
#if ASP_NET_CORE1 || ASP_NET_CORE2
#if ASP_NET_CORE2
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#endif
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#if !ASP_NET_CORE
using System.Web.Hosting;
#else
#if ASP_NET_CORE1 || ASP_NET_CORE2
#if ASP_NET_CORE2
using Microsoft.AspNetCore.Hosting;
using IHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#endif
Expand Down
34 changes: 1 addition & 33 deletions tests/NLog.Web.AspNetCore.Tests/AspNetCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void UseNLogShouldLogTest()
Assert.Equal("logger1|error1", logged.First());
}

#if !ASP_NET_CORE1
[Fact]
public void UseNLog_ReplaceLoggerFactory()
{
Expand All @@ -69,9 +68,8 @@ public void UseNLog_ReplaceLoggerFactory()
Assert.Equal(typeof(NLogLoggerFactory), loggerFactory.GetType());
Assert.Equal(typeof(NLogLoggerProvider), loggerProvider.GetType());
}
#endif

#if !ASP_NET_CORE1 && !ASP_NET_CORE2
#if !ASP_NET_CORE2
[Fact]
public void LoadConfigurationFromAppSettingsShouldLogTest()
{
Expand Down Expand Up @@ -214,7 +212,6 @@ public void RegisterHttpContext()
Assert.NotNull(webhost.Services.GetService<IHttpContextAccessor>());
}

#if !ASP_NET_CORE1
[Fact]
public void SkipRegisterHttpContext()
{
Expand Down Expand Up @@ -257,51 +254,22 @@ private static IWebHostBuilder CreateWebHostBuilder()
// Parameter name: applicationName
return builder;
}
#endif

/// <summary>
/// Create webhost with UseNlog
/// </summary>
/// <returns></returns>
private static IWebHost CreateWebHost(NLogAspNetCoreOptions options = null)
{
#if !ASP_NET_CORE1
return CreateWebHostBuilder()
.UseNLog(options)
.Build();
#else
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.Build();
return host;
#endif
}

private static ILoggerFactory GetLoggerFactory(IWebHost webhost)
{
return webhost.Services.GetService<Microsoft.Extensions.Logging.ILoggerFactory>();
}

#if ASP_NET_CORE1
public class Startup
{
public Startup()
{
}

public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.AddNLogWeb();
loggerFactory.AddNLog();
}

public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}
}
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp1.1;netcoreapp2.1;net461;netcoreapp3.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;net461;netcoreapp3.0</TargetFrameworks>
<AssemblyName>NLog.Web.AspNetCore.Tests</AssemblyName>
<AssemblyVersion>1.2.3.0</AssemblyVersion>
<FileVersion>1.2.3.1</FileVersion>
Expand All @@ -11,9 +11,6 @@
<AssemblyOriginatorKeyFile>../../NLog.snk</AssemblyOriginatorKeyFile>
<RootNamespace>NLog.Web.Tests</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE1</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' or '$(TargetFramework)' == 'net461' ">
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE2</DefineConstants>
Expand All @@ -32,9 +29,6 @@
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' or '$(TargetFramework)' == 'net461' ">
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.0" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions tests/Shared/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public TestBase()
#if ASP_NET_CORE
protected class HeaderDict : Dictionary<string, StringValues>, IHeaderDictionary
{
#if !ASP_NET_CORE1
/// <summary>
/// Strongly typed access to the Content-Length header. Implementations must keep this in sync with the string representation.
/// </summary>
Expand All @@ -28,7 +27,6 @@ public long? ContentLength
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
#endif
}
#endif
}
Expand Down

0 comments on commit 31cdd5b

Please sign in to comment.