/// <summary> /// Logs a stack event. /// </summary> /// <param name="event">The event.</param> public override void LogStackEvent(StackEvent @event) { const int TimeColWidth = 8; var stackColWidth = Math.Max(9, Math.Min(this.StackNameColumnWidth, 40)); var resourceColWidth = Math.Max(11, Math.Min(this.ResourceNameColumnWidth, 40)); var ui = this.cmdlet.Host.UI; var bg = ui.RawUI.BackgroundColor; if (this.isFirstEvent) { var eventFormatString = $"{{0,-{TimeColWidth}}} {{1,-{stackColWidth}}} {{2,-{resourceColWidth}}} {{3,-{this.StatusColumnWidth}}} {{4}}"; // Resize window to be wide enough for a reasonable amount of description per line this.ResizeWindow(string.Format(eventFormatString, "x", "x", "x", "x", Padding30).Length); this.isFirstEvent = false; this.LogInformation(eventFormatString, "Time", "StackName", "Logical ID", "Status", "Status Reason"); this.LogInformation(eventFormatString, "----", "---------", "----------", "------", "-------------"); } var leftIndent = GetLeftMarginForLastColumn( TimeColWidth, stackColWidth, resourceColWidth, this.StatusColumnWidth); var maxLineLength = ui.RawUI.WindowSize.Width - leftIndent; ui.Write($"{@event.Timestamp:HH:mm:ss} "); ui.Write(this.EllipsisString(@event.StackName, stackColWidth).PadRight(stackColWidth + 1)); ui.Write(this.EllipsisString(@event.LogicalResourceId, resourceColWidth).PadRight(resourceColWidth + 1)); var fg = ui.RawUI.ForegroundColor; var status = @event.ResourceStatus.Value; if (status.Contains("ROLLBACK") || ErrorStatus.IsMatch(status)) { fg = ConsoleColor.Red; } else if (status.EndsWith("IN_PROGRESS")) { fg = ConsoleColor.Cyan; } else if (status.EndsWith("COMPLETE")) { fg = ConsoleColor.Green; } ui.Write(fg, bg, status.PadRight(this.StatusColumnWidth + 1)); if (string.IsNullOrEmpty(@event.ResourceStatusReason)) { ui.WriteLine("-"); } else { fg = ErrorStatus.IsMatch(status) ? ConsoleColor.Red : ui.RawUI.ForegroundColor; // Split text to fit in space we have in the window var charCount = 0; var lines = @event.ResourceStatusReason.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .GroupBy(w => (charCount += w.Length + 1) / (maxLineLength - 1)).Select(g => string.Join(" ", g)) .ToList(); ui.WriteLine(fg, bg, lines.First()); foreach (var line in lines.Skip(1)) { ui.WriteLine(fg, bg, new string(' ', leftIndent) + line); } } }