Skip to content

Commit

Permalink
Merge pull request #433 from NLog/release/4.8.3
Browse files Browse the repository at this point in the history
Release 4.8.3
  • Loading branch information
304NotModified authored Jun 5, 2019
2 parents da1e926 + c265301 commit d6a51f5
Show file tree
Hide file tree
Showing 16 changed files with 244 additions and 157 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ See also [releases](https://github.com/NLog/NLog.Web/releases) and [milestones](

Date format: (year/month/day)



### v4.8.3 aspnetcore & aspnet4 (2019/06/05)
- [#428](https://github.com/NLog/NLog.Web/pull/428) Added AspNetLayoutRendererBase.Register for registering lambdas with httpcontext (@304NotModified)
- [#431](https://github.com/NLog/NLog.Web/pull/431) Fix NotSupportedException with ${aspnet-request-posted-body} (@304NotModified)

### v4.8.2 aspnetcore (2019/05/06)
- [#401](https://github.com/NLog/NLog.Web/pull/401) Fixed that ${aspnet-request-posted-body} could lead to "A non-empty request body is required." in ASP.NET Core 2 (@snakefoot, @304NotModified)
- [#401](https://github.com/NLog/NLog.Web/pull/401) Added MaxContentLength option to ${aspnet-request-posted-body} (@snakefoot, @304NotModified)
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 4.8.2.{build}
version: 4.8.3.{build}
clone_folder: c:\projects\nlogweb
configuration: Release
image: Visual Studio 2017
Expand All @@ -22,7 +22,7 @@ skip_tags: true

build_script:
- ps: |
$versionPrefix = "4.8.2"
$versionPrefix = "4.8.3"
$versionSuffix = ""
$versionBuild = $versionPrefix + "." + ${env:APPVEYOR_BUILD_NUMBER}
$versionNuget = $versionPrefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using NLog.Web.AspNetCore2.Example.Models;
using NLog.Web.LayoutRenderers;

namespace NLog.Web.AspNetCore2.Example.Controllers
{
Expand Down Expand Up @@ -32,11 +33,19 @@ public IActionResult About()
return View();
}

public IActionResult Contact()
public IActionResult Contact(bool posted = false)
{
ViewData["Message"] = "Your contact page.";
ViewData["Posted"] = posted;

return View();
return View(new MessageModel() { From = "me", Message = "My Message"});
}

[HttpPost]
public IActionResult PostMessage([FromForm] MessageModel messageModel)
{
_logger.LogInformation("Posted an message");
return RedirectToAction("Contact", new { posted = true });
}

public IActionResult Error()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NLog.Web.AspNetCore2.Example.Models
{
public class MessageModel
{
public string From { get; set; }
public string Message { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@{
@model NLog.Web.AspNetCore2.Example.Models.MessageModel

@{
ViewData["Title"] = "Contact";
}
<h2>@ViewData["Title"]</h2>
Expand All @@ -15,3 +17,24 @@
<strong>Support:</strong> <a href="mailto:Support@example.com">Support@example.com</a><br />
<strong>Marketing:</strong> <a href="mailto:Marketing@example.com">Marketing@example.com</a>
</address>

@if (ViewData["Posted"] is bool b && b)
{
<div>Message posted!</div>
}
else
{
<form asp-action="PostMessage" asp-controller="Home" method="post">
<div>
<input asp-for="From" placeholder="From" autofocus/>
</div>
<div>
<textarea asp-for="Message" placeholder="Message"></textarea>
</div>

<div>
<button type="submit">Post</button>
</div>

</form>
}
18 changes: 9 additions & 9 deletions src/NLog.Web.AspNetCore/NLog.Web.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Supported platforms:
<PackageId>NLog.Web.AspNetCore</PackageId>
<PackageTags>logging;log;session;NLog;web;aspnet;aspnetcore;MVC;httpcontext</PackageTags>
<PackageReleaseNotes>
- Fixed that ${aspnet-request-posted-body} could lead to "A non-empty request body is required." in ASP.NET Core 2 (@snakefoot, @304NotModified)
- Added MaxContentLength option to ${aspnet-request-posted-body} (@snakefoot, @304NotModified)
- Added AspNetLayoutRendererBase.Register for registering lambdas with httpcontext (@304NotModified)
- Fix NotSupportedException with ${aspnet-request-posted-body} (@304NotModified)
</PackageReleaseNotes>
<PackageIconUrl>https://nlog-project.org/N.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/NLog/NLog.Web</PackageProjectUrl>
Expand Down Expand Up @@ -58,21 +58,21 @@ Supported platforms:
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE2</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog.Extensions.Logging" Version="1.5.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.5.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' and '$(TargetFramework)' != 'net461' ">
<PackageReference Include="Microsoft.AspNetCore.Http" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="1.1.1" />
<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' ">
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\**\*.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/NLog.Web.AspNetCore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("74d5915b-bea9-404c-b4d0-b663164def37")]
[assembly:InternalsVisibleTo("NLog.Web.AspNetCore.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100ef8eab4fbdeb511eeb475e1659fe53f00ec1c1340700f1aa347bf3438455d71993b28b1efbed44c8d97a989e0cb6f01bcb5e78f0b055d311546f63de0a969e04cf04450f43834db9f909e566545a67e42822036860075a1576e90e1c43d43e023a24c22a427f85592ae56cac26f13b7ec2625cbc01f9490d60f16cfbb1bc34d9")]
[assembly: InternalsVisibleTo("NLog.Web.AspNetCore.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100772391e63c104728adcf18e2390474262559fa7f34a4215848f43288cde875dcc92a06222e9be0592b211ff74adbb5d21a7aab5522b540b1735f2f03279221056fedbe7e534073dabee9db48f8ecebcf1dc98a95576e45cbeff5fe7c4842859451ab2dae7a8370f1b2f7a529d2ca210e3e844d973523d73d193df6c17f1314a6")]
5 changes: 3 additions & 2 deletions src/NLog.Web/NLog.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ For ASP.NET Core: Check https://www.nuget.org/packages/NLog.Web.AspNetCore </Des
<PackageLicenseUrl>https://github.com/NLog/NLog.Web/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/NLog/NLog.Web</PackageProjectUrl>
<PackageReleaseNotes>
- Added ${aspnet-request-posted-body} - log posted request body/payload (@304NotModified)
- Added AspNetLayoutRendererBase.Register for registering lambdas with httpcontext (@304NotModified)
- Fix NotSupportedException with ${aspnet-request-posted-body} (@304NotModified)
</PackageReleaseNotes>
<PackageTags>nlog log target layoutrenderer web asp.net httpcontext</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -37,7 +38,7 @@ For ASP.NET Core: Check https://www.nuget.org/packages/NLog.Web.AspNetCore </Des
<AssemblyOriginatorKeyFile>NLog.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="4.5.11" />
<PackageReference Include="NLog" Version="4.6.4" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Configuration" />
Expand Down
1 change: 1 addition & 0 deletions src/NLog.Web/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("74d5915b-bea9-404c-b4d0-b663164def37")]
[assembly: InternalsVisibleTo("NLog.Web.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100772391e63c104728adcf18e2390474262559fa7f34a4215848f43288cde875dcc92a06222e9be0592b211ff74adbb5d21a7aab5522b540b1735f2f03279221056fedbe7e534073dabee9db48f8ecebcf1dc98a95576e45cbeff5fe7c4842859451ab2dae7a8370f1b2f7a529d2ca210e3e844d973523d73d193df6c17f1314a6")]
51 changes: 30 additions & 21 deletions src/Shared/LayoutRenderers/AspNetLayoutRendererBase.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
using System;
using System.Linq;
using System.Text;

using NLog.Common;
using NLog.Config;
using NLog.LayoutRenderers;
#if ASP_NET_CORE
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using NLog.Web.DependencyInjection;

using HttpContextBase = Microsoft.AspNetCore.Http.HttpContext;
#else
using System.Web;
#endif



namespace NLog.Web.LayoutRenderers
{
/// <summary>
/// Base class for ASP.NET layout renderers.
/// </summary>
public abstract class AspNetLayoutRendererBase : LayoutRenderer
{
/// <summary>
/// Initializes the <see cref="AspNetLayoutRendererBase" />.
/// </summary>
protected AspNetLayoutRendererBase()
{
#if !ASP_NET_CORE
HttpContextAccessor = new DefaultHttpContextAccessor();
#endif
}


#if ASP_NET_CORE

/// <summary>
/// Context for DI
/// </summary>
private IHttpContextAccessor _httpContextAccessor;


/// <summary>
/// Provides access to the current request HttpContext.
/// </summary>
Expand All @@ -47,6 +40,13 @@ public IHttpContextAccessor HttpContextAccessor
set => _httpContextAccessor = value;
}

#if !ASP_NET_CORE

internal static IHttpContextAccessor DefaultHttpContextAccessor { get; set; } = new DefaultHttpContextAccessor();

private static IHttpContextAccessor RetrieveHttpContextAccessor() => DefaultHttpContextAccessor;
#else

private static IHttpContextAccessor RetrieveHttpContextAccessor()
{
var serviceProvider = ServiceLocator.ServiceProvider;
Expand All @@ -73,12 +73,7 @@ private static IHttpContextAccessor RetrieveHttpContextAccessor()
}
}

#else
/// <summary>
/// Provides access to the current request HttpContext.
/// </summary>
[NLog.Config.NLogConfigurationIgnorePropertyAttribute]
public IHttpContextAccessor HttpContextAccessor { get; set; }


#endif

Expand Down Expand Up @@ -122,5 +117,19 @@ protected override void CloseLayoutRenderer()
base.CloseLayoutRenderer();
}
#endif


/// <summary>
/// Register a custom layout renderer with a callback function <paramref name="func" />. The callback recieves the logEvent and the current configuration.
/// </summary>
/// <param name="name">Name of the layout renderer - without ${}.</param>
/// <param name="func">Callback that returns the value for the layout renderer.</param>
public static void Register(string name, Func<LogEventInfo, HttpContextBase, LoggingConfiguration, object> func)
{
object NewFunc(LogEventInfo logEventInfo, LoggingConfiguration configuration) => func(logEventInfo, RetrieveHttpContextAccessor()?.HttpContext, configuration);

Register(name, NewFunc);
}
}
}
}

7 changes: 0 additions & 7 deletions src/Shared/LayoutRenderers/AspNetRequestPostedBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ private bool TryGetBody(HttpRequest httpRequest, long? contentLength, out Stream

if (!body.CanSeek)
{
var oldPosition = body.Position;
if (oldPosition > 0 && oldPosition >= contentLength)
{
InternalLogger.Debug("AspNetRequestPostedBody: body stream cannot seek and already read. StreamPosition={0}", oldPosition);
return false;
}

if (!TryEnableBuffering(httpRequest, contentLength, out body))
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<FileVersion>1.2.3.1</FileVersion>
<InformationalVersion>1.2.3.2</InformationalVersion>
<DebugType Condition=" '$(TargetFramework)' == 'net461' ">Full</DebugType>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../NLog.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
<DefineConstants>$(DefineConstants);ASP_NET_CORE;ASP_NET_CORE1</DefineConstants>
Expand All @@ -20,7 +23,7 @@
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
Expand All @@ -35,4 +38,4 @@
<Folder Include="Properties\" />
<Compile Include="..\Shared\**\*.cs" />
</ItemGroup>
</Project>
</Project>
6 changes: 4 additions & 2 deletions tests/NLog.Web.Tests/NLog.Web.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
<AssemblyVersion>1.2.3.0</AssemblyVersion>
<FileVersion>1.2.3.1</FileVersion>
<DebugType>full</DebugType>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../NLog.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.*" />
<PackageReference Include="System.ComponentModel.Composition" Version="4.*" />
<PackageReference Include="System.IO.Compression" Version="4.*" />
<PackageReference Include="System.Net.Http" Version="4.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="NSubstitute" Version="2.0.3" />
<PackageReference Include="NSubstitute" Version="4.2.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
Expand Down
Loading

0 comments on commit d6a51f5

Please sign in to comment.