| | | 1 | | using System.Collections.ObjectModel; |
| | | 2 | | using System.Management.Automation; |
| | | 3 | | using Kestrun.Logging.Enrichers.Extensions; |
| | | 4 | | |
| | | 5 | | namespace Kestrun.Logging.Data; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Wraps an ErrorRecord object to provide additional logging information. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// Initializes a new instance of the <see cref="ErrorRecordWrapper"/> class using the specified <see cref="ErrorRecord" |
| | | 12 | | /// </remarks> |
| | | 13 | | /// <param name="errorRecord">The error record to wrap.</param> |
| | 3 | 14 | | public class ErrorRecordWrapper(ErrorRecord errorRecord) |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets the error category information associated with the error record. |
| | | 18 | | /// </summary> |
| | 6 | 19 | | public ErrorCategoryInfo CategoryInfo { get; } = errorRecord.CategoryInfo; |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets or sets the error details associated with the error record. |
| | | 22 | | /// </summary> |
| | 5 | 23 | | public ErrorDetails ErrorDetails { get; set; } = errorRecord.ErrorDetails; |
| | | 24 | | /// <summary> |
| | | 25 | | /// Gets the fully qualified error ID associated with the error record. |
| | | 26 | | /// </summary> |
| | 6 | 27 | | public string FullyQualifiedErrorId { get; } = errorRecord.FullyQualifiedErrorId; |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets the invocation information wrapper associated with the error record. |
| | | 30 | | /// </summary> |
| | 7 | 31 | | public InvocationInfoWrapper InvocationInfoWrapper { get; } = new InvocationInfoWrapper(errorRecord.InvocationInfo); |
| | | 32 | | /// <summary> |
| | | 33 | | /// Gets the pipeline iteration information associated with the error record. |
| | | 34 | | /// </summary> |
| | 5 | 35 | | public ReadOnlyCollection<int> PipelineIterationInfo { get; } = errorRecord.PipelineIterationInfo; |
| | | 36 | | /// <summary> |
| | | 37 | | /// Gets the script stack trace associated with the error record. |
| | | 38 | | /// </summary> |
| | 5 | 39 | | public string ScriptStackTrace { get; } = errorRecord.ScriptStackTrace; |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets the target object associated with the error record. |
| | | 42 | | /// </summary> |
| | 5 | 43 | | public object TargetObject { get; } = errorRecord.TargetObject; |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets the exception message associated with the error record, if available. |
| | | 46 | | /// </summary> |
| | 5 | 47 | | public string? ExceptionMessage { get; } = errorRecord.Exception?.Message; |
| | | 48 | | /// <summary> |
| | | 49 | | /// Gets the exception details associated with the error record, if available. |
| | | 50 | | /// </summary> |
| | 5 | 51 | | public string? ExceptionDetails { get; } = errorRecord.Exception?.ToString(); |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Returns a string representation of the current <see cref="ErrorRecordWrapper"/> instance. |
| | | 55 | | /// </summary> |
| | | 56 | | /// <returns>A string representation of the error record wrapper.</returns> |
| | 1 | 57 | | public override string ToString() => this.ToTable(); |
| | | 58 | | } |