private static void LogTaskSummary(IEtlContext context, TaskExectionResult result, int longestTaskName) { var spacing1 = "".PadRight(longestTaskName - result.TaskName.Length); var spacing1WithoutName = "".PadRight(longestTaskName); if (result.Exceptions.Count == 0) { context.Log(LogSeverity.Information, null, "{Task}{spacing1} run-time is {Elapsed}, result is {Result}, CPU time: {CpuTime}, total allocations: {AllocatedMemory}, allocation difference: {MemoryDifference}", result.TaskName, spacing1, result.Statistics.RunTime, "success", result.Statistics.CpuTime, result.Statistics.TotalAllocations, result.Statistics.AllocationDifference); } else { context.Log(LogSeverity.Information, null, "{Task}{spacing1} run-time is {Elapsed}, result is {Result}, CPU time: {CpuTime}, total allocations: {AllocatedMemory}, allocation difference: {MemoryDifference}", result.TaskName, spacing1, result.Statistics.RunTime, "failed", result.Statistics.CpuTime, result.Statistics.TotalAllocations, result.Statistics.AllocationDifference); } if (result.IoCommandCounters.Count > 0) { var maxKeyLength = result.IoCommandCounters.Max(x => x.Key.ToString().Length); var maxInvocationLength = result.IoCommandCounters.Max(x => x.Value.InvocationCount.ToString(SerilogSink.ValueFormatter.DefaultIntegerFormat, CultureInfo.InvariantCulture).Length); foreach (var kvp in result.IoCommandCounters.OrderBy(kvp => kvp.Key.ToString())) { if (kvp.Value.AffectedDataCount != null) { context.Log(LogSeverity.Information, null, "{spacing1} {Kind}{spacing2} {InvocationCount}{spacing3} {AffectedDataCount}", spacing1WithoutName, kvp.Key.ToString(), "".PadRight(maxKeyLength - kvp.Key.ToString().Length, ' '), kvp.Value.InvocationCount, "".PadRight(maxInvocationLength - kvp.Value.InvocationCount.ToString(SerilogSink.ValueFormatter.DefaultIntegerFormat, CultureInfo.InvariantCulture).Length, ' '), kvp.Value.AffectedDataCount); } else { context.Log(LogSeverity.Information, null, "{spacing1} {Kind}{spacing2} {InvocationCount}", spacing1WithoutName, kvp.Key.ToString(), "".PadRight(maxKeyLength - kvp.Key.ToString().Length, ' '), kvp.Value.InvocationCount); } } } }
private static void LogTaskCounters(IEtlContext context, IEtlTask task) { if (task.IoCommandCounters.Count == 0) { return; } const string kind = "kind"; const string invocation = "invoc."; const string affected = "affected"; var maxKeyLength = Math.Max(kind.Length, task.IoCommandCounters.Max(x => x.Key.ToString().Length)); var maxInvocationLength = Math.Max(invocation.Length, task.IoCommandCounters.Max(x => x.Value.InvocationCount.ToString(SerilogSink.ValueFormatter.DefaultIntegerFormat, CultureInfo.InvariantCulture).Length)); context.Log(LogSeverity.Debug, task, "{Kind}{spacing1} {InvocationCount}{spacing2} {AffectedDataCount}", kind, "".PadRight(maxKeyLength - kind.Length, ' '), invocation, "".PadRight(maxInvocationLength - invocation.Length, ' '), affected); foreach (var kvp in task.IoCommandCounters.OrderBy(kvp => kvp.Key.ToString())) { if (kvp.Value.AffectedDataCount != null) { context.Log(LogSeverity.Debug, task, "{Kind}{spacing1} {InvocationCount}{spacing2} {AffectedDataCount}", kvp.Key.ToString(), "".PadRight(maxKeyLength - kvp.Key.ToString().Length, ' '), kvp.Value.InvocationCount, "".PadRight(maxInvocationLength - kvp.Value.InvocationCount.ToString(SerilogSink.ValueFormatter.DefaultIntegerFormat, CultureInfo.InvariantCulture).Length, ' '), kvp.Value.AffectedDataCount); } else { context.Log(LogSeverity.Debug, task, "{Kind}{spacing1} {InvocationCount}", kvp.Key.ToString(), "".PadRight(maxKeyLength - kvp.Key.ToString().Length, ' '), kvp.Value.InvocationCount); } } }