@@ -10,6 +10,8 @@ namespace WB.Logging.LogSinks.Console.Spectre;
1010/// </summary>
1111public static class ILoggerExtensions
1212{
13+ private static readonly ProgressConfiguration defaultProgressConfiguration = new ( ) ;
14+
1315 // ┌─────────────────────────────────────────────────────────────────────────────┐
1416 // │ Public Methods │
1517 // └─────────────────────────────────────────────────────────────────────────────┘
@@ -74,21 +76,22 @@ public static ILogger HorizontalRule(this ILogger @this, string? title = null)
7476 }
7577
7678 /// <summary>
77- /// Starts a progress with the specified <paramref name="title "/> and <paramref name="progress "/> function.
78- /// The progress will be automatically completed when the <paramref name="progress "/> function completes.
79+ /// Starts a progress with the <paramref name="progressConfiguration "/> running the specified <paramref name="action "/> function.
80+ /// The progress will be automatically completed when the <paramref name="action "/> function completes.
7981 /// </summary>
8082 /// <param name="this">The <see cref="ILogger"/> instance to start the progress on.</param>
81- /// <param name="title ">The title of the progress.</param>
82- /// <param name="progress ">The function that performs the progress.</param>
83+ /// <param name="progressConfiguration ">The configuration for the progress. This includes settings such as
84+ /// <param name="action ">The function that performs the progress.</param>
8385 /// <returns>A task that represents the asynchronous operation.</returns>
84- public static async Task StartProgressAsync ( this ILogger @this , string title , Func < ProgressContext , Task > progress )
86+ /// <seealso cref="ProgressConfiguration"/>
87+ public static async Task StartProgressAsync ( this ILogger @this , ProgressConfiguration progressConfiguration , Func < ProgressContext , Task > action )
8588 {
8689 ArgumentNullException . ThrowIfNull ( @this ) ;
8790
8891 ProgressPayload progressPayload = new ( )
8992 {
90- Title = title ,
91- Progress = progress ,
93+ Configuration = progressConfiguration ,
94+ Action = action ,
9295 } ;
9396
9497 await @this . FlushAsync ( ) . ConfigureAwait ( false ) ;
@@ -97,4 +100,40 @@ public static async Task StartProgressAsync(this ILogger @this, string title, Fu
97100
98101 await progressPayload . Completed . ConfigureAwait ( false ) ;
99102 }
103+
104+ /// <summary>
105+ /// Starts a progress running the specified <paramref name="action"/> function.
106+ /// The progress will be automatically completed when the <paramref name="action"/> function completes.
107+ /// </summary>
108+ /// <param name="this">The <see cref="ILogger"/> instance to start the progress on.</param>
109+ /// <param name="action">The function that performs the progress.</param>
110+ /// <returns>A task that represents the asynchronous operation.</returns>
111+ public static async Task StartProgressAsync ( this ILogger @this , Func < ProgressContext , Task > action )
112+ => await StartProgressAsync ( @this , defaultProgressConfiguration , action ) . ConfigureAwait ( false ) ;
113+
114+ public static async Task StartStatusAsync ( this ILogger @this , StatusConfiguration statusConfiguration , Func < StatusContext , Task > action )
115+ {
116+ ArgumentNullException . ThrowIfNull ( @this ) ;
117+
118+ StatusPayload statusPayload = new ( )
119+ {
120+ Configuration = statusConfiguration ,
121+ Action = action ,
122+ } ;
123+
124+ await @this . FlushAsync ( ) . ConfigureAwait ( false ) ;
125+
126+ @this . Log ( null , statusPayload ) ;
127+
128+ await statusPayload . Completed . ConfigureAwait ( false ) ;
129+ }
130+
131+ public static Task StartStatusAsync ( this ILogger @this , string statusMessage , Func < StatusContext , Task > action )
132+ {
133+ ArgumentNullException . ThrowIfNull ( @this ) ;
134+
135+ StatusConfiguration statusConfiguration = new ( statusMessage ) ;
136+
137+ return StartStatusAsync ( @this , statusConfiguration , action ) ;
138+ }
100139}
0 commit comments