Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Mar 27, 2019
2 parents de5ee97 + d67f404 commit de3ebd2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
53 changes: 37 additions & 16 deletions Source/StrongGrid/Utilities/DiagnosticHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,49 @@ public void OnRequest(IRequest request)
/// <param name="httpErrorAsException">Whether HTTP error responses should be raised as exceptions.</param>
public void OnResponse(IResponse response, bool httpErrorAsException)
{
var diagnosticInfo = GetDiagnosticInfo(response.Message.RequestMessage);
var diagnosticMessage = diagnosticInfo.Item1;
var timer = diagnosticInfo.Item2;
if (timer != null) timer.Stop();
var diagnosticMessage = string.Empty;

var httpResponse = response.Message;
try
{
var diagnosticInfo = GetDiagnosticInfo(response.Message.RequestMessage);
var diagnosticStringBuilder = diagnosticInfo.Item1;
var diagnosticTimer = diagnosticInfo.Item2;
if (diagnosticTimer != null) diagnosticTimer?.Stop();

diagnosticMessage.AppendLine($"Response: {httpResponse}");
diagnosticMessage.AppendLine($"Response Content: {httpResponse.Content?.ReadAsStringAsync(null).Result ?? "<NULL>"}");
var httpResponse = response.Message;

if (timer != null)
{
diagnosticMessage.AppendLine($"The request took {timer.Elapsed.ToDurationString()}");
}
diagnosticStringBuilder.AppendLine($"Response: {httpResponse}");
diagnosticStringBuilder.AppendLine($"Response Content: {httpResponse.Content?.ReadAsStringAsync(null).GetAwaiter().GetResult() ?? "<NULL>"}");

if (diagnosticTimer != null)
{
diagnosticStringBuilder.AppendLine($"The request took {diagnosticTimer.Elapsed.ToDurationString()}");
}

Debug.WriteLine("{0}\r\n{1}{0}", new string('=', 25), diagnosticMessage.ToString());
diagnosticMessage = diagnosticStringBuilder.ToString();
}
catch (Exception e)
{
Debug.WriteLine("{0}\r\nAN EXCEPTION OCCURED: {1}\r\n{0}", new string('=', 25), e.GetBaseException().Message);

if (_logger != null && _logger.IsDebugEnabled())
if (_logger != null && _logger.IsErrorEnabled())
{
_logger.Error(e, "An exception occured when inspecting the response from SendGrid");
}
}
finally
{
_logger.Debug(diagnosticMessage.ToString()
.Replace("{", "{{")
.Replace("}", "}}"));
if (!string.IsNullOrEmpty(diagnosticMessage))
{
Debug.WriteLine("{0}\r\n{1}{0}", new string('=', 25), diagnosticMessage);

if (_logger != null && _logger.IsDebugEnabled())
{
_logger.Debug(diagnosticMessage
.Replace("{", "{{")
.Replace("}", "}}"));
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions Source/StrongGrid/Utilities/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ void AppendFormatIfNecessary(StringBuilder stringBuilder, string timePart, int v
var result = new StringBuilder();
AppendFormatIfNecessary(result, "day", timeSpan.Days);
AppendFormatIfNecessary(result, "hour", timeSpan.Hours);
AppendFormatIfNecessary(result, "minute", timeSpan.Days);
AppendFormatIfNecessary(result, "second", timeSpan.Days);
AppendFormatIfNecessary(result, "millisecond", timeSpan.Days);
AppendFormatIfNecessary(result, "minute", timeSpan.Minutes);
AppendFormatIfNecessary(result, "second", timeSpan.Seconds);
AppendFormatIfNecessary(result, "millisecond", timeSpan.Milliseconds);
return result.ToString().Trim();
}

Expand Down

0 comments on commit de3ebd2

Please sign in to comment.