Skip to content

Commit

Permalink
Always remember to generate the code in the chain
Browse files Browse the repository at this point in the history
  • Loading branch information
woksin committed Mar 19, 2024
1 parent 64159fc commit abdd803
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Wolverine/Logging/LoggerBeginScopeWithAuditFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ public override IEnumerable<Variable> FindVariables(IMethodVariables chain)

public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
{
if (_members.Count == 0) return;
writer.WriteComment("Adding audited members to log context");
writer.Write(
$"using var disposable_{Guid.NewGuid().ToString().Replace("-", "_")} = {_logger!.Usage}.{nameof(ILogger.BeginScope)}"
+ $"(new {typeof(Dictionary<string, object>).FullNameInCode()}(){{{string.Join(", ", _members.Select(member => $"{{\"{member.MemberName}\", {_withAudit!.Usage}.{member.Member.Name}}}"))}}});");
if (_members.Count > 0)
{
writer.WriteComment("Adding audited members to log context");
writer.Write(
$"using var disposable_{Guid.NewGuid().ToString().Replace("-", "_")} = {_logger!.Usage}.{nameof(ILogger.BeginScope)}"
+ $"(new {typeof(Dictionary<string, object>).FullNameInCode()}(){{{string.Join(", ", _members.Select(member => $"{{\"{member.MemberName}\", {_withAudit!.Usage}.{member.Member.Name}}}"))}}});");
}

Next?.GenerateCode(method, writer);
}
Expand Down

0 comments on commit abdd803

Please sign in to comment.