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

Re-remove NetEventSource.IsEnabled property #47917

Merged
merged 1 commit into from
Feb 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#nullable enable
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Tracing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -99,7 +98,7 @@ public static void Info(object? thisOrContextObject, FormattableString? formatta
{
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);
}

/// <summary>Logs an information message.</summary>
Expand All @@ -111,7 +110,7 @@ public static void Info(object? thisOrContextObject, object? message, [CallerMem
{
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)]
Expand All @@ -129,7 +128,7 @@ public static void Error(object? thisOrContextObject, FormattableString formatta
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString));
if (Log.IsEnabled()) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString));
}

/// <summary>Logs an error message.</summary>
Expand All @@ -141,7 +140,7 @@ public static void Error(object? thisOrContextObject, object message, [CallerMem
{
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)]
Expand All @@ -159,7 +158,7 @@ public static void Verbose(object? thisOrContextObject, FormattableString format
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
if (IsEnabled) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString));
if (Log.IsEnabled()) Log.ErrorMessage(IdOf(thisOrContextObject), memberName, Format(formattableString));
}

/// <summary>Logs an info at verbose mode.</summary>
Expand All @@ -171,7 +170,7 @@ public static void Verbose(object? thisOrContextObject, object message, [CallerM
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(message);
if (IsEnabled) Log.VerboseMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString());
if (Log.IsEnabled()) Log.VerboseMessage(IdOf(thisOrContextObject), memberName, Format(message).ToString());
}

[Event(ErrorEventId, Level = EventLevel.Verbose, Keywords = Keywords.Default)]
Expand Down Expand Up @@ -199,7 +198,7 @@ public static void DumpBuffer(object? thisOrContextObject, byte[] buffer, [Calle
[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);

Expand All @@ -225,7 +224,7 @@ public static unsafe void DumpBuffer(object? thisOrContextObject, IntPtr bufferP
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)
Expand All @@ -251,7 +250,7 @@ public static void Associate(object first, object second, [CallerMemberName] str
{
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));
}

/// <summary>Logs a relationship between two objects.</summary>
Expand All @@ -265,7 +264,7 @@ public static void Associate(object? thisOrContextObject, object first, object s
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}]")]
Expand All @@ -278,7 +277,7 @@ private void Associate(string thisOrContextObject, string? memberName, string fi
[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");
Expand All @@ -288,12 +287,9 @@ private static void DebugValidateArg(object? arg)
[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;

Expand Down Expand Up @@ -381,7 +377,7 @@ private static string Format(FormattableString s)
[NonEvent]
private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3, string? arg4)
{
if (IsEnabled())
if (Log.IsEnabled())
{
if (arg1 == null) arg1 = "";
if (arg2 == null) arg2 = "";
Expand Down Expand Up @@ -425,7 +421,7 @@ private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string?
[NonEvent]
private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, byte[]? arg3)
{
if (IsEnabled())
if (Log.IsEnabled())
{
if (arg1 == null) arg1 = "";
if (arg2 == null) arg2 = "";
Expand Down Expand Up @@ -468,7 +464,7 @@ private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, byte[]?
[NonEvent]
private unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3, int arg4)
{
if (IsEnabled())
if (Log.IsEnabled())
{
if (arg1 == null) arg1 = "";

Expand Down Expand Up @@ -506,7 +502,7 @@ private unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3, in
[NonEvent]
private unsafe void WriteEvent(int eventId, string? arg1, int arg2, string? arg3)
{
if (IsEnabled())
if (Log.IsEnabled())
{
if (arg1 == null) arg1 = "";
if (arg3 == null) arg3 = "";
Expand Down Expand Up @@ -541,7 +537,7 @@ private unsafe void WriteEvent(int eventId, string? arg1, int arg2, string? arg3
[NonEvent]
private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, int arg3)
{
if (IsEnabled())
if (Log.IsEnabled())
{
if (arg1 == null) arg1 = "";
if (arg2 == null) arg2 = "";
Expand Down Expand Up @@ -576,7 +572,7 @@ private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, int arg3
[NonEvent]
private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3, int arg4)
{
if (IsEnabled())
if (Log.IsEnabled())
{
if (arg1 == null) arg1 = "";
if (arg2 == null) arg2 = "";
Expand Down Expand Up @@ -618,7 +614,7 @@ private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string?
[NonEvent]
private unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8)
{
if (IsEnabled())
if (Log.IsEnabled())
{
if (arg1 == null) arg1 = "";

Expand Down Expand Up @@ -676,7 +672,7 @@ private unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3, int
[NonEvent]
private unsafe void WriteEvent(int eventId, string arg1, string arg2, int arg3, int arg4, int arg5)
{
if (IsEnabled())
if (Log.IsEnabled())
{
if (arg1 == null) arg1 = "";
if (arg2 == null) arg2 = "";
Expand Down