Skip to content

Commit

Permalink
Add more verbose logging (#67)
Browse files Browse the repository at this point in the history
* Adding more verbose logs
  • Loading branch information
satbai authored Feb 14, 2019
1 parent 5e07558 commit 70be3b8
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CredentialProviderVersion>0.1.11</CredentialProviderVersion>
<CredentialProviderVersion>0.1.12</CredentialProviderVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public override Task<GetAuthenticationCredentialsResponse> HandleRequestAsync(Ge
string uriPrefixesString = Environment.GetEnvironmentVariable(EnvUtil.BuildTaskUriPrefixes);
string accessToken = Environment.GetEnvironmentVariable(EnvUtil.BuildTaskAccessToken);

Verbose(string.Format(Resources.IsRetry, request.IsRetry));

string[] uriPrefixes = uriPrefixesString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
Verbose(Resources.BuildTaskUriPrefixes);
foreach (var uriPrefix in uriPrefixes)
Expand All @@ -58,7 +60,7 @@ public override Task<GetAuthenticationCredentialsResponse> HandleRequestAsync(Ge

string uriString = request.Uri.ToString();
string matchedPrefix = uriPrefixes.FirstOrDefault(prefix => uriString.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
Verbose(string.Format(Resources.BuildTaskMatchedPrefix, matchedPrefix));
Verbose(string.Format(Resources.BuildTaskMatchedPrefix, matchedPrefix != null ? matchedPrefix : Resources.BuildTaskNoMatchingPrefixes));

if (matchedPrefix == null)
{
Expand All @@ -70,6 +72,7 @@ public override Task<GetAuthenticationCredentialsResponse> HandleRequestAsync(Ge
MessageResponseCode.Error);
}

Verbose(string.Format(Resources.BuildTaskEndpointMatchingUrlFound, uriString));
return this.GetResponse(
Username,
accessToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public override Task<GetAuthenticationCredentialsResponse> HandleRequestAsync(Ge
{
cancellationToken.ThrowIfCancellationRequested();

Verbose(string.Format(Resources.IsRetry, request.IsRetry));

string uriString = request.Uri.ToString();
bool endpointFound = Credentials.TryGetValue(uriString, out EndpointCredentials matchingEndpoint);
if (endpointFound)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,19 @@ public async Task HandleResponseAsync(IConnection connection, Message message, I
}
catch (Exception ex) when (cancellationToken.IsCancellationRequested)
{
Logger.Verbose(string.Format(Resources.RequestHandlerCancelingExceptionMessage, ex.InnerException, ex.Message));
Logger.Verbose(Resources.CancellationRequested);

// We have been canceled by NuGet. Send a cancellation response.
var cancelMessage = MessageUtilities.Create(message.RequestId, MessageType.Cancel, message.Method);
await connection.SendAsync(cancelMessage, CancellationToken.None);

Logger.Verbose(ex.ToString());


// We must guarantee that exactly one terminating message is sent, so do not fall through to send
// the normal response, but also do not rethrow.
return;
}

Logger.Verbose(string.Format(Resources.SendingResponse, message.Type, message.Method));
// If we did not send a cancel message, we must submit the response even if cancellationToken is canceled.
await responseHandler.SendResponseAsync(message, response, CancellationToken.None).ConfigureAwait(continueOnCapturedContext: false);
}
Expand All @@ -87,6 +90,7 @@ bool LogExceptionAndReturnFalse(Exception ex)
// don't report cancellations during shutdown, they're most likely not interesting.
if (ex is OperationCanceledException && Program.IsShuttingDown && !Debugger.IsAttached)
{
Logger.Verbose(Resources.ShuttingDown);
return false;
}

Expand Down
38 changes: 37 additions & 1 deletion CredentialProvider.Microsoft/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion CredentialProvider.Microsoft/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
<value>Running in stand-alone mode</value>
</data>
<data name="SendingResponse" xml:space="preserve">
<value>Sending response: '{0}'</value>
<value>Sending response: '{0}' '{1}'</value>
</data>
<data name="SessionTokenCacheDisabled" xml:space="preserve">
<value>SessionToken cache disabled by environment</value>
Expand Down Expand Up @@ -418,4 +418,16 @@ Device Flow Authentication Timeout
<data name="CacheException" xml:space="preserve">
<value>Exception happened when trying to get cached token. Invalidating cache. Message: {0}</value>
</data>
<data name="CancellationRequested" xml:space="preserve">
<value>Cancellation requested. Sending cancellation response.</value>
</data>
<data name="BuildTaskNoMatchingPrefixes" xml:space="preserve">
<value>none</value>
</data>
<data name="RequestHandlerCancelingExceptionMessage" xml:space="preserve">
<value>Cancellation exception happened while handling request. Exception: {0}, Message: {1}</value>
</data>
<data name="ShuttingDown" xml:space="preserve">
<value>Credential provider shutting down.</value>
</data>
</root>

0 comments on commit 70be3b8

Please sign in to comment.