Skip to content

Commit

Permalink
[RFT] Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
proudmonkey committed Nov 18, 2019
1 parent fe133d8 commit 459ac0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions AutoWrapper/AutoWrapperMembers.cs
Expand Up @@ -210,7 +210,7 @@ public Task WrapIgnoreAsync(HttpContext context, object body)
{
var bodyText = !body.ToString().IsValidJson() ? ConvertToJSONString(body) : body.ToString();
context.Response.ContentType = "application/json";
context.Response.ContentLength = bodyText != null ? System.Text.Encoding.UTF8.GetByteCount(bodyText) : 0;
context.Response.ContentLength = bodyText != null ? Encoding.UTF8.GetByteCount(bodyText) : 0;
return context.Response.WriteAsync(bodyText);
}

Expand All @@ -220,7 +220,7 @@ private Task WriteFormattedResponseToHttpContext(HttpContext context, int code,
{
context.Response.StatusCode = code;
context.Response.ContentType = "application/json";
context.Response.ContentLength = jsonString != null ? System.Text.Encoding.UTF8.GetByteCount(jsonString) : 0;
context.Response.ContentLength = jsonString != null ? Encoding.UTF8.GetByteCount(jsonString) : 0;
return context.Response.WriteAsync(jsonString);
}

Expand Down
12 changes: 8 additions & 4 deletions AutoWrapper/Base/WrapperBase.cs
Expand Up @@ -84,16 +84,20 @@ public virtual async Task InvokeAsyncBase(HttpContext context, AutoWrapperMember
}
finally
{
stopWatch.Stop();

if (_options.EnableResponseLogging)
_logger.Log(LogLevel.Information, $@"Source:[{context.Connection.RemoteIpAddress.ToString() }] Request: {request} Responded with [{context.Response.StatusCode}] in {stopWatch.ElapsedMilliseconds}ms");
LogResponse(context, request, stopWatch);
}
}

}

}

private void LogResponse(HttpContext context, string request, Stopwatch stopWatch)
{
stopWatch.Stop();
if (_options.EnableResponseLogging)
_logger.Log(LogLevel.Information, $@"Source:[{context.Connection.RemoteIpAddress.ToString() }] Request: {request} Responded with [{context.Response.StatusCode}] in {stopWatch.ElapsedMilliseconds}ms");
}
}

}

0 comments on commit 459ac0f

Please sign in to comment.