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

Revamp the logging generator to use the new redaction model. #4233

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
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 @@ -6,11 +6,34 @@

namespace Microsoft.Extensions.Telemetry.Bench;

internal static partial class ClassicCodeGen
#pragma warning disable S103
#pragma warning disable SA1121
#pragma warning disable S2148
#pragma warning disable IDE0055
#pragma warning disable IDE1006
#pragma warning disable S3235

internal static class ClassicCodeGen
{
[LoggerMessage(LogLevel.Error, @"Connection id '{connectionId}' received {type} frame for stream ID {streamId} with length {length} and flags {flags} and {other}")]
public static partial void RefTypes(ILogger logger, string connectionId, string type, string streamId, string length, string flags, string other);
private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.String, global::System.String, global::System.String, global::System.String, global::System.String, global::System.String, global::System.Exception?> __RefTypesCallback =
global::Microsoft.Extensions.Logging.LoggerMessage.Define<global::System.String, global::System.String, global::System.String, global::System.String, global::System.String, global::System.String>(global::Microsoft.Extensions.Logging.LogLevel.Error, new global::Microsoft.Extensions.Logging.EventId(2037881459, nameof(RefTypes)), "Connection id '{connectionId}' received {type} frame for stream ID {streamId} with length {length} and flags {flags} and {other}", new global::Microsoft.Extensions.Logging.LogDefineOptions() { SkipEnabledCheck = true });

public static void RefTypes(global::Microsoft.Extensions.Logging.ILogger logger, global::System.String connectionId, global::System.String type, global::System.String streamId, global::System.String length, global::System.String flags, global::System.String other)
{
if (logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Error))
{
__RefTypesCallback(logger, connectionId, type, streamId, length, flags, other, null);
}
}

private static readonly global::System.Action<global::Microsoft.Extensions.Logging.ILogger, global::System.Int64, global::System.Int64, global::System.Int32, global::System.Guid, global::System.Exception?> __ValueTypesCallback =
global::Microsoft.Extensions.Logging.LoggerMessage.Define<global::System.Int64, global::System.Int64, global::System.Int32, global::System.Guid>(global::Microsoft.Extensions.Logging.LogLevel.Error, new global::Microsoft.Extensions.Logging.EventId(558429541, nameof(ValueTypes)), "Range [{start}..{end}], options {options}, guid {guid}", new global::Microsoft.Extensions.Logging.LogDefineOptions() { SkipEnabledCheck = true });

[LoggerMessage(LogLevel.Error, @"Range [{start}..{end}], options {options}, guid {guid}")]
public static partial void ValueTypes(ILogger logger, long start, long end, int options, Guid guid);
public static void ValueTypes(global::Microsoft.Extensions.Logging.ILogger logger, global::System.Int64 start, global::System.Int64 end, global::System.Int32 options, global::System.Guid guid)
{
if (logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Error))
{
__ValueTypesCallback(logger, start, end, options, guid, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,63 @@ internal static class ModernCodeGen
public static void RefTypes(global::Microsoft.Extensions.Logging.ILogger logger, string connectionId, string type, string streamId, string length, string flags, string other)
{
var state = global::Microsoft.Extensions.Telemetry.Logging.LoggerMessageHelper.ThreadLocalState;
var index = state.ReservePropertySpace(7);
var array = state.PropertyArray;
array[index++] = new("connectionId", connectionId);
array[index++] = new("type", type);
array[index++] = new("streamId", streamId);
array[index++] = new("length", length);
array[index++] = new("flags", flags);
array[index++] = new("other", other);
array[index] = new("{OriginalFormat}", "Connection id '{connectionId}' received {type} frame for stream ID {streamId} with length {length} and flags {flags} and {other}");

_ = state.ReservePropertySpace(7);
state.PropertyArray[6] = new("connectionId", connectionId);
state.PropertyArray[5] = new("type", type);
state.PropertyArray[4] = new("streamId", streamId);
state.PropertyArray[3] = new("length", length);
state.PropertyArray[2] = new("flags", flags);
state.PropertyArray[1] = new("other", other);
state.PropertyArray[0] = new("{OriginalFormat}", "Connection id '{connectionId}' received {type} frame for stream ID {streamId} with length {length} and flags {flags} and {other}");

logger.Log(
global::Microsoft.Extensions.Logging.LogLevel.Error,
new global::Microsoft.Extensions.Logging.EventId(0, nameof(RefTypes)),
state,
null, // Refer to our docs to learn how to pass exception here
__FMT_0_RefTypes_Error);
null,
static (s, _) =>
{
var connectionId = s.PropertyArray[6].Value ?? "(null)";
var type = s.PropertyArray[5].Value ?? "(null)";
var streamId = s.PropertyArray[4].Value ?? "(null)";
var length = s.PropertyArray[3].Value ?? "(null)";
var flags = s.PropertyArray[2].Value ?? "(null)";
var other = s.PropertyArray[1].Value ?? "(null)";
return global::System.FormattableString.Invariant($"Connection id '{connectionId}' received {type} frame for stream ID {streamId} with length {length} and flags {flags} and {other}");
});

state.Clear();
}

private static string __FMT_0_RefTypes_Error(global::Microsoft.Extensions.Telemetry.Logging.LoggerMessageState _h, global::System.Exception? _)
{
var connectionId = _h.PropertyArray[0].Value ?? "(null)";
var type = _h.PropertyArray[1].Value ?? "(null)";
var streamId = _h.PropertyArray[2].Value ?? "(null)";
var length = _h.PropertyArray[3].Value ?? "(null)";
var flags = _h.PropertyArray[4].Value ?? "(null)";
var other = _h.PropertyArray[5].Value ?? "(null)";
return global::System.FormattableString.Invariant($"Connection id '{connectionId}' received {type} frame for stream ID {streamId} with length {length} and flags {flags} and {other}");
}

/// <summary>
/// Logs "Range [{start}..{end}], options {options}, guid {guid}" at "Error" level.
/// </summary>
public static void ValueTypes(global::Microsoft.Extensions.Logging.ILogger logger, long start, long end, int options, global::System.Guid guid)
{
var state = global::Microsoft.Extensions.Telemetry.Logging.LoggerMessageHelper.ThreadLocalState;
var index = state.ReservePropertySpace(5);
var array = state.PropertyArray;
array[index++] = new("start", start);
array[index++] = new("end", end);
array[index++] = new("options", options);
array[index++] = new("guid", guid.ToString());
array[index] = new("{OriginalFormat}", "Range [{start}..{end}], options {options}, guid {guid}");

_ = state.ReservePropertySpace(5);
state.PropertyArray[4] = new("start", start);
state.PropertyArray[3] = new("end", end);
state.PropertyArray[2] = new("options", options);
state.PropertyArray[1] = new("guid", guid.ToString());
state.PropertyArray[0] = new("{OriginalFormat}", "Range [{start}..{end}], options {options}, guid {guid}");

logger.Log(
global::Microsoft.Extensions.Logging.LogLevel.Error,
new global::Microsoft.Extensions.Logging.EventId(0, nameof(ValueTypes)),
state,
null, // Refer to our docs to learn how to pass exception here
__FMT_2_ValueTypes_Error);
null,
static (s, _) =>
{
var start = s.PropertyArray[4].Value;
var end = s.PropertyArray[3].Value;
var options = s.PropertyArray[2].Value;
var guid = s.PropertyArray[1].Value;
return global::System.FormattableString.Invariant($"Range [{start}..{end}], options {options}, guid {guid}");
});

state.Clear();
}

private static string __FMT_2_ValueTypes_Error(global::Microsoft.Extensions.Telemetry.Logging.LoggerMessageState _h, global::System.Exception? _)
{
var start = _h.PropertyArray[0].Value;
var end = _h.PropertyArray[1].Value;
var options = _h.PropertyArray[2].Value;
var guid = _h.PropertyArray[3].Value;
return global::System.FormattableString.Invariant($"Range [{start}..{end}], options {options}, guid {guid}");
}
}
Loading