| | 1 | | using Kestrun.Logging.Data; |
| | 2 | | using Kestrun.Logging.Utils.Console; |
| | 3 | | using Kestrun.Logging.Utils.Console.Extensions; |
| | 4 | |
|
| | 5 | |
|
| | 6 | | namespace Kestrun.Logging.Enrichers.Extensions; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// Provides extension methods for formatting error records and invocation info as tables. |
| | 10 | | /// </summary> |
| | 11 | | public static class ErrorRecordExtensions |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Formats the specified <see cref="ErrorRecordWrapper"/> as a table string. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="errorRecord">The error record to format.</param> |
| | 17 | | /// <returns>A string representation of the error record as a table.</returns> |
| | 18 | | public static string ToTable(this ErrorRecordWrapper errorRecord) |
| | 19 | | { |
| 1 | 20 | | var table = new Table(new Padding(1)); |
| | 21 | |
|
| 1 | 22 | | table.AddPropertyRow("CategoryInfo", errorRecord.CategoryInfo); |
| 1 | 23 | | table.AddPropertyRow("ErrorDetails", errorRecord.ErrorDetails); |
| 1 | 24 | | table.AddPropertyRow("FullyQualifiedErrorId", errorRecord.FullyQualifiedErrorId); |
| 1 | 25 | | table.AddPropertyRow("PipelineIterationInfo", string.Join(";", errorRecord.PipelineIterationInfo)); |
| 1 | 26 | | table.AddPropertyRow("ScriptStackTrace", errorRecord.ScriptStackTrace); |
| 1 | 27 | | table.AddPropertyRow("TargetObject", errorRecord.TargetObject); |
| | 28 | |
|
| 1 | 29 | | return table.ToString(); |
| | 30 | | } |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Formats the specified <see cref="InvocationInfoWrapper"/> as a table string. |
| | 34 | | /// </summary> |
| | 35 | | /// <param name="invocationInfo">The invocation info to format.</param> |
| | 36 | | /// <returns>A string representation of the invocation info as a table.</returns> |
| | 37 | | public static string ToTable(this InvocationInfoWrapper invocationInfo) |
| | 38 | | { |
| 1 | 39 | | var table = new Table(new Padding(1)); |
| | 40 | |
|
| 1 | 41 | | var boundParams = string.Join(", ", invocationInfo.BoundParameters.Select(kv => $"{kv.Key}:{kv.Value}")); |
| 1 | 42 | | table.AddPropertyRow("BoundParameters", boundParams); |
| 1 | 43 | | table.AddPropertyRow("CommandOrigin", invocationInfo.CommandOrigin); |
| 1 | 44 | | table.AddPropertyRow("DisplayScriptPosition", invocationInfo.DisplayScriptPosition); |
| 1 | 45 | | table.AddPropertyRow("ExpectingInput", invocationInfo.ExpectingInput); |
| 1 | 46 | | table.AddPropertyRow("HistoryId", invocationInfo.HistoryId); |
| 1 | 47 | | table.AddPropertyRow("InvocationName", invocationInfo.InvocationName); |
| 1 | 48 | | table.AddPropertyRow("Line", invocationInfo.Line); |
| 1 | 49 | | table.AddPropertyRow("MyCommand", invocationInfo.MyCommand ?? string.Empty); |
| 1 | 50 | | table.AddPropertyRow("OffsetInLine", invocationInfo.OffsetInLine); |
| 1 | 51 | | table.AddPropertyRow("PipelineLength", invocationInfo.PipelineLength); |
| 1 | 52 | | table.AddPropertyRow("PipelinePosition", invocationInfo.PipelinePosition); |
| 1 | 53 | | table.AddPropertyRow("PSCommandPath", invocationInfo.PSCommandPath); |
| 1 | 54 | | table.AddPropertyRow("PSScriptRoot", invocationInfo.PSScriptRoot); |
| 1 | 55 | | table.AddPropertyRow("ScriptLineNumber", invocationInfo.ScriptLineNumber); |
| 1 | 56 | | table.AddPropertyRow("ScriptName", invocationInfo.ScriptName); |
| 1 | 57 | | table.AddPropertyRow("UnboundArguments", string.Join("; ", invocationInfo.UnboundArguments)); |
| | 58 | |
|
| 1 | 59 | | return table.ToString(); |
| | 60 | | } |
| | 61 | | } |