From: Stephen Toub Date: Thu, 19 Nov 2020 19:50:16 +0000 (-0500) Subject: Delete NetEventSource.IsEnabled (#44901) X-Git-Tag: submit/tizen/20210909.063632~4516 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8bbbf6d673dee68890b39995303d2054765a0eed;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Delete NetEventSource.IsEnabled (#44901) * Delete NetEventSource.IsEnabled These were all meant to be changed to NetEventSource.Log.IsEnabled(), and there are almost 900 occurrences of that pattern. But there are still 9 stragglers, and the method itself. Deleting the method and fixing the call sites. * Fix uses in NetEventSource itself --- diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/SSPIWrapper.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/SSPIWrapper.cs index 43d9d05..d99bd95 100644 --- a/src/libraries/Common/src/Interop/Windows/SspiCli/SSPIWrapper.cs +++ b/src/libraries/Common/src/Interop/Windows/SspiCli/SSPIWrapper.cs @@ -118,7 +118,7 @@ namespace System.Net if (errorCode != 0) { - if (NetEventSource.IsEnabled) NetEventSource.Error(null, SR.Format(SR.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}")); + if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(null, SR.Format(SR.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}")); throw new Win32Exception(errorCode); } diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs index b69d628..76539c8 100644 --- a/src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs +++ b/src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs @@ -307,7 +307,7 @@ namespace System.Net.Security ref outCredential._handle, out timeStamp); - if (NetEventSource.IsEnabled) NetEventSource.Verbose(null, $"{nameof(Interop.SspiCli.AcquireCredentialsHandleW)} returns 0x{errorCode:x}, handle = {outCredential}"); + if (NetEventSource.Log.IsEnabled()) NetEventSource.Verbose(null, $"{nameof(Interop.SspiCli.AcquireCredentialsHandleW)} returns 0x{errorCode:x}, handle = {outCredential}"); if (errorCode != 0) { diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/NetEventSource.Common.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/NetEventSource.Common.cs index 174ad40..6905c66 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/NetEventSource.Common.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/NetEventSource.Common.cs @@ -95,7 +95,7 @@ namespace System.Net { DebugValidateArg(thisOrContextObject); DebugValidateArg(formattableString); - if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); + if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); } /// Logs entrance to a method. @@ -107,7 +107,7 @@ namespace System.Net { DebugValidateArg(thisOrContextObject); DebugValidateArg(arg0); - if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)})"); + if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)})"); } /// Logs entrance to a method. @@ -121,7 +121,7 @@ namespace System.Net DebugValidateArg(thisOrContextObject); DebugValidateArg(arg0); DebugValidateArg(arg1); - if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)})"); + if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)})"); } /// Logs entrance to a method. @@ -137,7 +137,7 @@ namespace System.Net DebugValidateArg(arg0); DebugValidateArg(arg1); DebugValidateArg(arg2); - if (IsEnabled) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)}, {Format(arg2)})"); + if (Log.IsEnabled()) Log.Enter(IdOf(thisOrContextObject), memberName, $"({Format(arg0)}, {Format(arg1)}, {Format(arg2)})"); } [Event(EnterEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)] @@ -155,7 +155,7 @@ namespace System.Net { DebugValidateArg(thisOrContextObject); DebugValidateArg(formattableString); - if (IsEnabled) Log.Exit(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); + if (Log.IsEnabled()) Log.Exit(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); } /// Logs exit from a method. @@ -167,7 +167,7 @@ namespace System.Net { DebugValidateArg(thisOrContextObject); DebugValidateArg(arg0); - if (IsEnabled) Log.Exit(IdOf(thisOrContextObject), memberName, Format(arg0).ToString()); + if (Log.IsEnabled()) Log.Exit(IdOf(thisOrContextObject), memberName, Format(arg0).ToString()); } /// Logs exit from a method. @@ -181,7 +181,7 @@ namespace System.Net DebugValidateArg(thisOrContextObject); DebugValidateArg(arg0); DebugValidateArg(arg1); - if (IsEnabled) Log.Exit(IdOf(thisOrContextObject), memberName, $"{Format(arg0)}, {Format(arg1)}"); + if (Log.IsEnabled()) Log.Exit(IdOf(thisOrContextObject), memberName, $"{Format(arg0)}, {Format(arg1)}"); } [Event(ExitEventId, Level = EventLevel.Informational, Keywords = Keywords.EnterExit)] @@ -199,7 +199,7 @@ namespace System.Net { DebugValidateArg(thisOrContextObject); DebugValidateArg(formattableString); - if (IsEnabled) Log.Info(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); + if (Log.IsEnabled()) Log.Info(IdOf(thisOrContextObject), memberName, formattableString != null ? Format(formattableString) : NoParameters); } /// Logs an information message. @@ -211,7 +211,7 @@ namespace System.Net { DebugValidateArg(thisOrContextObject); DebugValidateArg(message); - if (IsEnabled) Log.Info(IdOf(thisOrContextObject), memberName, Format(message).ToString()); + if (Log.IsEnabled()) Log.Info(IdOf(thisOrContextObject), memberName, Format(message).ToString()); } [Event(InfoEventId, Level = EventLevel.Informational, Keywords = Keywords.Default)] @@ -229,7 +229,7 @@ namespace System.Net { DebugValidateArg(thisOrContextObject); DebugValidateArg(formattableString); - if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString)); + if (Log.IsEnabled()) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString)); } /// Logs an error message. @@ -241,7 +241,7 @@ namespace System.Net { DebugValidateArg(thisOrContextObject); DebugValidateArg(message); - if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString()); + if (Log.IsEnabled()) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString()); } [Event(ErrorEventId, Level = EventLevel.Error, Keywords = Keywords.Default)] @@ -269,7 +269,7 @@ namespace System.Net [NonEvent] public static void DumpBuffer(object? thisOrContextObject, byte[] buffer, int offset, int count, [CallerMemberName] string? memberName = null) { - if (IsEnabled && offset >= 0 && offset <= buffer.Length - count) + if (Log.IsEnabled() && offset >= 0 && offset <= buffer.Length - count) { count = Math.Min(count, MaxDumpSize); @@ -295,7 +295,7 @@ namespace System.Net Debug.Assert(bufferPtr != IntPtr.Zero); Debug.Assert(count >= 0); - if (IsEnabled) + if (Log.IsEnabled()) { var buffer = new byte[Math.Min(count, MaxDumpSize)]; fixed (byte* targetPtr = buffer) @@ -321,7 +321,7 @@ namespace System.Net { DebugValidateArg(first); DebugValidateArg(second); - if (IsEnabled) Log.Associate(IdOf(first), memberName, IdOf(first), IdOf(second)); + if (Log.IsEnabled()) Log.Associate(IdOf(first), memberName, IdOf(first), IdOf(second)); } /// Logs a relationship between two objects. @@ -335,7 +335,7 @@ namespace System.Net DebugValidateArg(thisOrContextObject); DebugValidateArg(first); DebugValidateArg(second); - if (IsEnabled) Log.Associate(IdOf(thisOrContextObject), memberName, IdOf(first), IdOf(second)); + if (Log.IsEnabled()) Log.Associate(IdOf(thisOrContextObject), memberName, IdOf(first), IdOf(second)); } [Event(AssociateEventId, Level = EventLevel.Informational, Keywords = Keywords.Default, Message = "[{2}]<-->[{3}]")] @@ -348,7 +348,7 @@ namespace System.Net [Conditional("DEBUG_NETEVENTSOURCE_MISUSE")] private static void DebugValidateArg(object? arg) { - if (!IsEnabled) + if (!Log.IsEnabled()) { Debug.Assert(!(arg is ValueType), $"Should not be passing value type {arg?.GetType()} to logging without IsEnabled check"); Debug.Assert(!(arg is FormattableString), $"Should not be formatting FormattableString \"{arg}\" if tracing isn't enabled"); @@ -358,12 +358,9 @@ namespace System.Net [Conditional("DEBUG_NETEVENTSOURCE_MISUSE")] private static void DebugValidateArg(FormattableString? arg) { - Debug.Assert(IsEnabled || arg == null, $"Should not be formatting FormattableString \"{arg}\" if tracing isn't enabled"); + Debug.Assert(Log.IsEnabled() || arg == null, $"Should not be formatting FormattableString \"{arg}\" if tracing isn't enabled"); } - public static new bool IsEnabled => - Log.IsEnabled(); - [NonEvent] public static string IdOf(object? value) => value != null ? value.GetType().Name + "#" + GetHashCode(value) : NullInstance; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs index d9f03e9..eefd608 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs @@ -743,7 +743,7 @@ namespace System.Net.Http _recvBuffer.Discard(bytesRead); - if (NetEventSource.IsEnabled) + if (NetEventSource.Log.IsEnabled()) { Trace($"Received frame {frameType} of length {payloadLength}."); } diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs index 3cdf343..e9dd2d8 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs @@ -412,7 +412,7 @@ namespace System.Net } } - if (cancelResult != 0 && cancelResult != Interop.Winsock.WSA_INVALID_HANDLE && NetEventSource.IsEnabled) + if (cancelResult != 0 && cancelResult != Interop.Winsock.WSA_INVALID_HANDLE && NetEventSource.Log.IsEnabled()) { NetEventSource.Info(@this, $"GetAddrInfoExCancel returned error {cancelResult}"); } diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicStream.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicStream.cs index 0069a23..5379f1f 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicStream.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicStream.cs @@ -225,7 +225,7 @@ namespace System.Net.Quic.Implementations.MsQuic throw new InvalidOperationException("Reading is not allowed on stream."); } - if (NetEventSource.IsEnabled) + if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(this, $"[{GetHashCode()}] reading into Memory of '{destination.Length}' bytes."); } @@ -479,7 +479,7 @@ namespace System.Net.Quic.Implementations.MsQuic private uint HandleEvent(ref StreamEvent evt) { - if (NetEventSource.IsEnabled) + if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(this, $"[{GetHashCode()}] handling event '{evt.Type}'."); } diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.Windows.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.Windows.cs index 0827eca..fcb84b2 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.Windows.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.Windows.cs @@ -62,7 +62,7 @@ namespace System.Net.Security { store.Dispose(); store = null; - if (NetEventSource.IsEnabled) + if (NetEventSource.Log.IsEnabled()) { NetEventSource.Error(this, $"Failed to open certificate store for intermediates."); } diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.cs index 4cba323..37f3e03 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.cs @@ -33,7 +33,7 @@ namespace System.Net.Security chain.ChainPolicy.DisableCertificateDownloads = offline; bool chainStatus = chain.Build(target); - if (!chainStatus && NetEventSource.IsEnabled) + if (!chainStatus && NetEventSource.Log.IsEnabled()) { NetEventSource.Error(null, $"Failed to build chain for {target.Subject}"); } diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamPal.Windows.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamPal.Windows.cs index 89b474f..b93e899 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamPal.Windows.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslStreamPal.Windows.cs @@ -216,7 +216,7 @@ namespace System.Net.Security credential.paCred = &certificateHandle; } - if (NetEventSource.IsEnabled) NetEventSource.Info($"flags=({flags}), ProtocolFlags=({protocolFlags}), EncryptionPolicy={policy}"); + if (NetEventSource.Log.IsEnabled()) NetEventSource.Info($"flags=({flags}), ProtocolFlags=({protocolFlags}), EncryptionPolicy={policy}"); if (protocolFlags != 0) {