Add more logging for authentication failure (dotnet/corefx#31225)
authorCaesar Chen <caesar1995@users.noreply.github.com>
Fri, 20 Jul 2018 23:51:02 +0000 (16:51 -0700)
committerGitHub <noreply@github.com>
Fri, 20 Jul 2018 23:51:02 +0000 (16:51 -0700)
* add logging

* address feedback

* feedback 2

* change Info to Error

Commit migrated from https://github.com/dotnet/corefx/commit/3ea1a8cf78073491f9532e36a738a7b8be44829a

src/libraries/System.Net.Security/src/System/Net/Security/SecureChannel.cs

index f969d49..cfe0a16 100644 (file)
@@ -738,8 +738,16 @@ namespace System.Net.Security
             }
 
             ProtocolToken token = new ProtocolToken(nextmsg, status);
+
             if (NetEventSource.IsEnabled)
+            {
+                if (token.Failed)
+                {
+                    NetEventSource.Error(this, $"Authentication failed. Status: {status.ToString()}, Exception message: {token.GetException().Message}");
+                }
+
                 NetEventSource.Exit(this, token);
+            }
             return token;
         }
 
@@ -760,9 +768,8 @@ namespace System.Net.Security
         --*/
         private SecurityStatusPal GenerateToken(byte[] input, int offset, int count, ref byte[] output)
         {
-#if TRACE_VERBOSE
             if (NetEventSource.IsEnabled) NetEventSource.Enter(this, $"_refreshCredentialNeeded = {_refreshCredentialNeeded}");
-#endif
+
             if (offset < 0 || offset > (input == null ? 0 : input.Length))
             {
                 NetEventSource.Fail(this, "Argument 'offset' out of range.");
@@ -873,6 +880,11 @@ namespace System.Net.Security
             byte[] alpnResult = SslStreamPal.GetNegotiatedApplicationProtocol(_securityContext);
             _negotiatedApplicationProtocol = alpnResult == null ? default : new SslApplicationProtocol(alpnResult, false);
 
+            if (NetEventSource.IsEnabled)
+            {
+                NetEventSource.Exit(this);
+            }
+
             return status;
         }