使用日志中间件方法
让我们回到错误尚未修复的初始状态,面对看似正确的查询,我们都傻眼了。
调试查询的另一个方法是使用以下扩展方法:
public static IEnumerable<T> LogLINQ<T>(this IEnumerable<T> enumerable, string logName, System.Func<T, string> printMethod)
{
#if DEBUG
int count = 0;
foreach (var item in enumerable)
{
if (printMethod != null)
{
System.Diagnostics.Debug.WriteLine($"{logName}|item {count} = {printMethod(item)}");
}
count++;
yield return item;
}
System.Diagnostics.Debug.WriteLine($"{logName}|count = {count}");
#else
return enumerable;
#endif
}