messaging
Tudor Stanciu 2019-11-04 00:53:41 +02:00
parent 8a2133a2d3
commit 5dc9919263
2 changed files with 10 additions and 7 deletions

View File

@ -7,6 +7,7 @@
<RepositoryUrl>https://dev.azure.com/tstanciu94/_git/NDB</RepositoryUrl> <RepositoryUrl>https://dev.azure.com/tstanciu94/_git/NDB</RepositoryUrl>
<PackageReleaseNotes>.NET standard library for logging stuff in an API.</PackageReleaseNotes> <PackageReleaseNotes>.NET standard library for logging stuff in an API.</PackageReleaseNotes>
<PackageTags>NDB NDB.Logging</PackageTags> <PackageTags>NDB NDB.Logging</PackageTags>
<Version>1.0.2</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -25,7 +25,7 @@ namespace NDB.Logging.Api
stopWatch.Start(); stopWatch.Start();
var uid = Guid.NewGuid(); var uid = Guid.NewGuid();
var request = ((DefaultHttpRequest)((ControllerBase)context.Controller).Request); var request = (HttpRequest)((ControllerBase)context.Controller).Request;
var requestUrl = request.Path; var requestUrl = request.Path;
if (request.QueryString != null && request.QueryString.HasValue) if (request.QueryString != null && request.QueryString.HasValue)
@ -51,16 +51,18 @@ namespace NDB.Logging.Api
_logger.LogDebug($"Request {uid} duration: {stopWatch.ElapsedMilliseconds:N0} ms"); _logger.LogDebug($"Request {uid} duration: {stopWatch.ElapsedMilliseconds:N0} ms");
} }
private async Task<string> GetRequestBody(DefaultHttpRequest request) private async Task<string> GetRequestBody(HttpRequest request)
{ {
if (request.ContentLength == 0) if (request.ContentLength == 0)
return "-"; return "-";
var body = new StreamReader(request.Body); using (var body = new StreamReader(request.Body))
body.BaseStream.Seek(0, SeekOrigin.Begin); {
var bodyStr = await body.ReadToEndAsync(); body.BaseStream.Seek(0, SeekOrigin.Begin);
var bodyStr = await body.ReadToEndAsync();
return bodyStr; return bodyStr;
}
} }
} }
} }