@@ -74,6 +74,32 @@ public static ILogger HorizontalRule(this ILogger @this, string? title = null)
7474 return @this ;
7575 }
7676
77+ public static async Task ProgressAsync ( this ILogger @this , Func < Progress , Task > action , CancellationToken cancellationToken = default )
78+ {
79+ ArgumentNullException . ThrowIfNull ( @this ) ;
80+ ArgumentNullException . ThrowIfNull ( action ) ;
81+
82+ ProgressStartPayload startPayload = new ( )
83+ {
84+ CancellationToken = cancellationToken ,
85+ } ;
86+
87+ @this . Log ( null , startPayload ) ;
88+
89+ Progress progress = await startPayload . WaitForProgressAsync ( ) . ConfigureAwait ( false ) ;
90+
91+ await action ( progress ) . ConfigureAwait ( false ) ;
92+
93+ ProgressFinishedPayload finishedPayload = new ( )
94+ {
95+ CancellationToken = cancellationToken ,
96+ } ;
97+
98+ @this . Log ( null , finishedPayload ) ;
99+
100+ await finishedPayload . WaitForFinishedAsync ( ) . ConfigureAwait ( false ) ;
101+ }
102+
77103 /// <summary>
78104 /// Starts a progress with the <paramref name="progressConfiguration"/> running the specified <paramref name="action"/> function.
79105 /// The progress will be automatically completed when the <paramref name="action"/> function completes.
@@ -112,7 +138,7 @@ public static async Task StartProgressAsync(this ILogger @this, Action<Progress>
112138 public static async Task StartProgressAsync ( this ILogger @this , Func < ProgressContext , CancellationToken , Task > action , CancellationToken cancellationToken = default )
113139 => await StartProgressAsync ( @this , _ => { } , action , cancellationToken ) . ConfigureAwait ( false ) ;
114140
115- public static async Task StartStatusAsync ( this ILogger @this , string message , Action < Status > status , Func < StatusContext , Task > action )
141+ public static async Task StartStatusAsync ( this ILogger @this , string message , Action < Status > status , Func < StatusContext , CancellationToken , Task > action , CancellationToken cancellationToken = default )
116142 {
117143 ArgumentNullException . ThrowIfNull ( @this ) ;
118144
@@ -121,15 +147,16 @@ public static async Task StartStatusAsync(this ILogger @this, string message, Ac
121147 StatusConfigurationAction = status ,
122148 StatusAction = action ,
123149 StatusMessage = message ,
150+ CancellationToken = cancellationToken ,
124151 } ;
125152
126- await @this . FlushAsync ( ) . ConfigureAwait ( false ) ;
153+ await @this . FlushAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
127154
128155 @this . Log ( null , statusPayload ) ;
129156
130157 await statusPayload . Completed . ConfigureAwait ( false ) ;
131158 }
132159
133160 public static Task StartStatusAsync ( this ILogger @this , string statusMessage , Func < StatusContext , Task > action )
134- => StartStatusAsync ( @this , statusMessage , _ => { } , action ) ;
161+ => StartStatusAsync ( @this , statusMessage , _ => { } , ( context , cancellationToken ) => action ( context ) , CancellationToken . None ) ;
135162}
0 commit comments