diff --git a/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Controllers/HomeController.cs b/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Controllers/HomeController.cs index ab7d351a..4c67555e 100644 --- a/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Controllers/HomeController.cs +++ b/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Controllers/HomeController.cs @@ -31,6 +31,13 @@ public IActionResult Privacy() return View(); } + [HttpPost] + public IActionResult AddItem(ItemModel model) + { + _logger.LogInformation("Added item {@Model}", model); + return View("Index"); + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Models/ItemModel.cs b/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Models/ItemModel.cs new file mode 100644 index 00000000..763e9a6a --- /dev/null +++ b/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Models/ItemModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace ASP.NET_Core_3___VS2019.Models +{ + public class ItemModel + { + public string Name { get; set; } + public string Value { get; set; } + + } +} diff --git a/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/NLog.config b/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/NLog.config index dd61f616..af7839ae 100644 --- a/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/NLog.config +++ b/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/NLog.config @@ -19,7 +19,7 @@ + layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}|${callsite}| body: ${aspnet-request-posted-body}" /> diff --git a/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Views/Home/Index.cshtml b/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Views/Home/Index.cshtml index d2d19bdf..87e4f63e 100644 --- a/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Views/Home/Index.cshtml +++ b/examples/ASP.NET Core 3/ASP.NET Core 3 - VS2019/Views/Home/Index.cshtml @@ -5,4 +5,10 @@

Welcome

Learn about building Web apps with ASP.NET Core.

+ +
+ + + +
diff --git a/src/Shared/LayoutRenderers/AspNetRequestPostedBody.cs b/src/Shared/LayoutRenderers/AspNetRequestPostedBody.cs index 90cbacf7..13888da3 100644 --- a/src/Shared/LayoutRenderers/AspNetRequestPostedBody.cs +++ b/src/Shared/LayoutRenderers/AspNetRequestPostedBody.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Text; +using System.Threading; using NLog.Common; using NLog.Config; using NLog.LayoutRenderers; @@ -10,6 +11,7 @@ using System.Web; using HttpRequest = System.Web.HttpRequestBase; #else +using System.Threading.Tasks; using HttpRequest = Microsoft.AspNetCore.Http.HttpRequest; #endif @@ -70,7 +72,12 @@ private static string BodyToString(Stream body) // Note: don't dispose the StreamReader, it will close the stream and that's unwanted. You could pass that that // to the StreamReader in some platforms, but then the dispose will be a NOOP, so for platform compat just don't dispose var bodyReader = new StreamReader(body); + +#if ASP_NET_CORE + var content = bodyReader.ReadToEndAsync().ConfigureAwait(false).GetAwaiter().GetResult(); +#else var content = bodyReader.ReadToEnd(); +#endif return content; } finally