Skip to content

Commit

Permalink
Modified ConsoleLogger to output array parameter values
Browse files Browse the repository at this point in the history
  • Loading branch information
slovely authored and jeremydmiller committed Nov 27, 2023
1 parent b2cf293 commit 3b53f27
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Marten/IMartenLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using Marten.Services;
Expand Down Expand Up @@ -87,7 +88,22 @@ public void LogSuccess(NpgsqlCommand command)
{
Console.WriteLine(command.CommandText);
foreach (var p in command.Parameters.OfType<NpgsqlParameter>())
Console.WriteLine($" {p.ParameterName}: {p.Value}");
Console.WriteLine($" {p.ParameterName}: {GetParameterValue(p)}");
}

private static object? GetParameterValue(NpgsqlParameter p)
{
if (p.Value is IList enumerable)
{
var result = "";
for (var i = 0; i < Math.Min(enumerable.Count, 5); i++)
{
result += $"[{i}] {enumerable[i]}; ";
}
if (enumerable.Count > 5) result += $" + {enumerable.Count - 5} more";
return result;
}
return p.Value;
}

public void LogFailure(NpgsqlCommand command, Exception ex)
Expand Down

0 comments on commit 3b53f27

Please sign in to comment.