Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardization of Event Source tracing + Improvements for readability #484

Merged
merged 14 commits into from
Mar 24, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private static bool CompareInsensitiveInvariant(string strvalue, string strconst
[System.Diagnostics.Conditional("DEBUG")]
private static void DebugTraceKeyValuePair(string keyname, string keyvalue, Dictionary<string, string> synonyms)
{
if (SqlClientEventSource.Log.IsAdvanceTraceOn())
if (SqlClientEventSource.Log.IsAdvancedTraceOn())
{
Debug.Assert(string.Equals(keyname, keyname?.ToLower(), StringComparison.InvariantCulture), "missing ToLower");
string realkeyname = ((null != synonyms) ? (string)synonyms[keyname] : keyname);
Expand All @@ -171,11 +171,11 @@ private static void DebugTraceKeyValuePair(string keyname, string keyvalue, Dict
// don't trace passwords ever!
if (null != keyvalue)
{
SqlClientEventSource.Log.AdvanceTrace("<comm.DbConnectionOptions|INFO|ADV> KeyName='{0}', KeyValue='{1}'", keyname, keyvalue);
SqlClientEventSource.Log.AdvancedTraceEvent("<comm.DbConnectionOptions|INFO|ADV> KeyName='{0}', KeyValue='{1}'", keyname, keyvalue);
}
else
{
SqlClientEventSource.Log.AdvanceTrace("<comm.DbConnectionOptions|INFO|ADV> KeyName='{0}'", keyname);
SqlClientEventSource.Log.AdvancedTraceEvent("<comm.DbConnectionOptions|INFO|ADV> KeyName='{0}'", keyname);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ internal DbConnectionPoolGroup GetConnectionPoolGroup(DbConnectionPoolKey key, D
private void PruneConnectionPoolGroups(object state)
{
// when debugging this method, expect multiple threads at the same time
SqlClientEventSource.Log.AdvanceTrace("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}#", ObjectID);
SqlClientEventSource.Log.AdvancedTraceEvent("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}#", ObjectID);

// First, walk the pool release list and attempt to clear each
// pool, when the pool is finally empty, we dispose of it. If the
Expand All @@ -323,7 +323,7 @@ private void PruneConnectionPoolGroups(object state)
if (0 == pool.Count)
{
_poolsToRelease.Remove(pool);
SqlClientEventSource.Log.AdvanceTrace("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}#, ReleasePool={1}#", ObjectID, pool.ObjectID);
SqlClientEventSource.Log.AdvancedTraceEvent("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}#, ReleasePool={1}#", ObjectID, pool.ObjectID);
}
}
}
Expand All @@ -347,7 +347,7 @@ private void PruneConnectionPoolGroups(object state)
if (0 == poolsLeft)
{
_poolGroupsToRelease.Remove(poolGroup);
SqlClientEventSource.Log.AdvanceTrace("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}#, ReleasePoolGroup={1}#", ObjectID, poolGroup.ObjectID);
SqlClientEventSource.Log.AdvancedTraceEvent("<prov.DbConnectionFactory.PruneConnectionPoolGroups|RES|INFO|CPOOL> {0}#, ReleasePoolGroup={1}#", ObjectID, poolGroup.ObjectID);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ static private void TraceException(
Debug.Assert(null != e, "TraceException: null Exception");
if (null != e)
{
SqlClientEventSource.Log.AdvanceTrace(trace, e.Message);
SqlClientEventSource.Log.AdvanceTrace("<comm.ADP.TraceException|ERR|ADV> Environment StackTrace = '{0}'", Environment.StackTrace);
SqlClientEventSource.Log.AdvancedTraceEvent(trace, e.Message);
SqlClientEventSource.Log.AdvancedTraceEvent("<comm.ADP.TraceException|ERR|ADV> Environment StackTrace = '{0}'", Environment.StackTrace);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,26 @@ internal static uint MapLocalDBErrorStateToCode(LocalDBErrorState errorState)
switch (errorState)
{
case LocalDBErrorState.NO_INSTALLATION:
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > LocalDB is not installed. Error State ={0}", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > LocalDB is not installed. Error State ={0}", errorState);
return SNICommon.LocalDBNoInstallation;

case LocalDBErrorState.INVALID_CONFIG:
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > Invalid configuration. Error State ={0}", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > Invalid configuration. Error State ={0}", errorState);
return SNICommon.LocalDBInvalidConfig;

case LocalDBErrorState.NO_SQLUSERINSTANCEDLL_PATH:
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > No SQL user instance path. Error State ={0}", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > No SQL user instance path. Error State ={0}", errorState);
return SNICommon.LocalDBNoSqlUserInstanceDllPath;

case LocalDBErrorState.INVALID_SQLUSERINSTANCEDLL_PATH:
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > Invalid SQL user instance path. Error State ={0}", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > Invalid SQL user instance path. Error State ={0}", errorState);
return SNICommon.LocalDBInvalidSqlUserInstanceDllPath;

case LocalDBErrorState.NONE:
return 0;

default:
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > Invalid configuration. Error State ={0}", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.MapLocalDBErrorStateToCode |SNI|ERR > Invalid configuration. Error State ={0}", errorState);
return SNICommon.LocalDBInvalidConfig;
}
}
Expand All @@ -93,7 +93,7 @@ internal static uint MapLocalDBErrorStateToCode(LocalDBErrorState errorState)
/// </summary>
private bool LoadUserInstanceDll()
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.LocalDB.Windows.LoadUserInstanceDll |SNI>");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.LocalDB.Windows.LoadUserInstanceDll |SNI>");
try
{
// Check in a non thread-safe way if the handle is already set for performance.
Expand Down Expand Up @@ -126,7 +126,7 @@ private bool LoadUserInstanceDll()
if (string.IsNullOrWhiteSpace(dllPath))
{
SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBInvalidSqlUserInstanceDllPath, string.Empty);
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.LoadUserInstanceDll |SNI|ERR > User instance DLL path is invalid. DLL path ={0}", dllPath);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.LoadUserInstanceDll |SNI|ERR > User instance DLL path is invalid. DLL path ={0}", dllPath);
return false;
}

Expand Down Expand Up @@ -181,7 +181,7 @@ private bool LoadUserInstanceDll()
/// <returns></returns>
private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|SCOPE|INFO > GetUserInstanceDllPath");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|SCOPE|INFO > GetUserInstanceDllPath");
try
{
string dllPath = null;
Expand All @@ -190,7 +190,7 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
if (key == null)
{
errorState = LocalDBErrorState.NO_INSTALLATION;
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > not installed. Error state ={0}.", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > not installed. Error state ={0}.", errorState);
return null;
}

Expand All @@ -205,7 +205,7 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
if (!Version.TryParse(subKey, out currentKeyVersion))
{
errorState = LocalDBErrorState.INVALID_CONFIG;
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > Invalid Configuration. state ={0}.", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > Invalid Configuration. state ={0}.", errorState);
return null;
}

Expand All @@ -219,7 +219,7 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
if (latestVersion.Equals(zeroVersion))
{
errorState = LocalDBErrorState.INVALID_CONFIG;
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > Invalid Configuration. state ={0}.", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > Invalid Configuration. state ={0}.", errorState);
return null;
}

Expand All @@ -232,7 +232,7 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
if (instanceAPIPathRegistryObject == null)
{
errorState = LocalDBErrorState.NO_SQLUSERINSTANCEDLL_PATH;
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > No SQL user instance DLL. Instance API Path REgistry Object Error. state ={0}.", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > No SQL user instance DLL. Instance API Path REgistry Object Error. state ={0}.", errorState);
return null;
}

Expand All @@ -241,7 +241,7 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState)
if (valueKind != RegistryValueKind.String)
{
errorState = LocalDBErrorState.INVALID_SQLUSERINSTANCEDLL_PATH;
SqlClientEventSource.Log.SNITrace("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > No SQL user instance DLL. state ={0}. Registry value kind error.", errorState);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.LocalDB.Windows.GetUserInstanceDllPath |SNI|ERR > No SQL user instance DLL. state ={0}. Registry value kind error.", errorState);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ internal class SNICommon
/// <returns>True if certificate is valid</returns>
internal static bool ValidateSslServerCertificate(string targetServerName, object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors policyErrors)
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNICommon.ValidateSslServerCertificate |SNI|SCOPE|INFO >");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNICommon.ValidateSslServerCertificate |SNI|SCOPE|INFO >");
try
{
if (policyErrors == SslPolicyErrors.None)
Expand Down Expand Up @@ -203,7 +203,7 @@ internal static bool ValidateSslServerCertificate(string targetServerName, objec
/// <returns></returns>
internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uint sniError, string errorMessage)
{
SqlClientEventSource.Log.SNITrace("<sc.SNI.SNICommon. ReportSNIError |SNI|ERR > Provider ={0}, native Error ={1}, SNI Error ={2}, Error Message ={3}", provider, nativeError, sniError, errorMessage);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.SNICommon. ReportSNIError |SNI|ERR > Provider ={0}, native Error ={1}, SNI Error ={2}, Error Message ={3}", provider, nativeError, sniError, errorMessage);
return ReportSNIError(new SNIError(provider, nativeError, sniError, errorMessage));
}

Expand All @@ -216,7 +216,7 @@ internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uin
/// <returns></returns>
internal static uint ReportSNIError(SNIProviders provider, uint sniError, Exception sniException)
{
SqlClientEventSource.Log.SNITrace("<sc.SNI.SNICommon. ReportSNIError |SNI|ERR > Provider ={0}, SNI Error ={2}, Exception ={3}", provider, sniError, sniException.Message);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.SNICommon. ReportSNIError |SNI|ERR > Provider ={0}, SNI Error ={2}, Exception ={3}", provider, sniError, sniException.Message);
return ReportSNIError(new SNIError(provider, sniError, sniException));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SNIError LastError

set
{
SqlClientEventSource.Log.SNITrace("<sc.SNI.SNILoadHandle.LastError |SNI|INFO|SETTER > Last Error Value = {0}", value);
SqlClientEventSource.Log.SNITraceEvent("<sc.SNI.SNILoadHandle.LastError |SNI|INFO|SETTER > Last Error Value = {0}", value);
_lastError.Value = value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public SNIMarsHandle CreateMarsSession(object callbackObject, bool async)
/// <returns></returns>
public uint StartReceive()
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNIMarsConnection.StartReceive |SNI|INFO|SCOPE> StartReceive");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.StartReceive |SNI|INFO|SCOPE> StartReceive");
try
{
SNIPacket packet = null;
Expand All @@ -88,7 +88,7 @@ public uint StartReceive()
/// <returns>SNI error code</returns>
public uint Send(SNIPacket packet)
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNIMarsConnection.Send |SNI|INFO|SCOPE> Send");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.Send |SNI|INFO|SCOPE> Send");
try
{
lock (this)
Expand All @@ -110,7 +110,7 @@ public uint Send(SNIPacket packet)
/// <returns>SNI error code</returns>
public uint SendAsync(SNIPacket packet, SNIAsyncCallback callback)
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNIMarsConnection.SendAsync |SNI|INFO|SCOPE> SendAsync");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.SendAsync |SNI|INFO|SCOPE> SendAsync");
try
{
lock (this)
Expand All @@ -131,7 +131,7 @@ public uint SendAsync(SNIPacket packet, SNIAsyncCallback callback)
/// <returns>SNI error code</returns>
public uint ReceiveAsync(ref SNIPacket packet)
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNIMarsConnection.SendAsync |SNI|INFO|SCOPE> SendAsync");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.SendAsync |SNI|INFO|SCOPE> SendAsync");
try
{
if (packet != null)
Expand All @@ -157,7 +157,7 @@ public uint ReceiveAsync(ref SNIPacket packet)
/// <returns>SNI error status</returns>
public uint CheckConnection()
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNIMarsConnection.CheckConnection |SNI|INFO|SCOPE>");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.CheckConnection |SNI|INFO|SCOPE>");
try
{
lock (this)
Expand Down Expand Up @@ -208,7 +208,7 @@ public void HandleSendComplete(SNIPacket packet, uint sniErrorCode)
/// <param name="sniErrorCode">SNI error code</param>
public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode)
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNIMarsConnection.HandleReceiveComplete |SNI|INFO|SCOPE>");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.HandleReceiveComplete |SNI|INFO|SCOPE>");
try
{
SNISMUXHeader currentHeader = null;
Expand Down Expand Up @@ -352,7 +352,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode)
/// </summary>
public uint EnableSsl(uint options)
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNIMarsConnection.EnableSsl |SNI|INFO|SCOPE>");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.EnableSsl |SNI|INFO|SCOPE>");
try
{
return _lowerHandle.EnableSsl(options);
Expand All @@ -368,7 +368,7 @@ public uint EnableSsl(uint options)
/// </summary>
public void DisableSsl()
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNIMarsConnection.EnableSsl |SNI|INFO|SCOPE>");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.EnableSsl |SNI|INFO|SCOPE>");
try
{
_lowerHandle.DisableSsl();
Expand All @@ -385,7 +385,7 @@ public void DisableSsl()
/// </summary>
public void KillConnection()
{
long scopeID = SqlClientEventSource.Log.SNIScopeEnter("<sc.SNI.SNIMarsConnection.KillConnection |SNI|INFO|SCOPE>");
long scopeID = SqlClientEventSource.Log.SNIScopeEnterEvent("<sc.SNI.SNIMarsConnection.KillConnection |SNI|INFO|SCOPE>");
try
{
_lowerHandle.KillConnection();
Expand Down
Loading