@@ -8,28 +8,45 @@ namespace GitVersion.Logging;
88/// </summary>
99internal static class LoggerExtensions
1010{
11+ private const string Indentation = "│ " ;
12+ private static readonly AsyncLocal < string > CurrentIndentation = new ( ) ;
13+
14+ /// <summary>
15+ /// Gets the current indentation string for log messages.
16+ /// Used by IndentationEnricher to add indentation to all log messages within a scope.
17+ /// </summary>
18+ internal static string GetIndentation ( ) => CurrentIndentation . Value ?? string . Empty ;
19+
1120 /// <summary>
1221 /// Provides extension methods for <see cref="ILogger"/> instances.
1322 /// </summary>
1423 extension ( ILogger logger )
1524 {
1625 /// <summary>
1726 /// Begins a timed operation scope that logs the start and end times with duration.
27+ /// All log messages within this scope will be indented.
1828 /// </summary>
1929 /// <param name="operationDescription">A description of the operation being timed.</param>
2030 /// <returns>An <see cref="IDisposable"/> that logs the end of the operation when disposed.</returns>
21- public IDisposable BeginTimedOperation ( string operationDescription )
31+ public IDisposable StartIndentedScope ( string operationDescription )
2232 {
2333 ArgumentNullException . ThrowIfNull ( logger ) ;
2434
2535 var start = TimeProvider . System . GetTimestamp ( ) ;
26- logger . LogInformation ( "-< Begin: {OperationDescription} >-" , operationDescription ) ;
36+ logger . LogInformation ( "┌─── Begin: {OperationDescription}" , operationDescription ) ;
37+
38+ // Capture current indentation and increase it for nested logs
39+ var previousIndentation = CurrentIndentation . Value ?? string . Empty ;
40+ CurrentIndentation . Value = previousIndentation + Indentation ;
2741
2842 return Disposable . Create ( ( ) =>
2943 {
44+ // Restore previous indentation before logging the End message
45+ CurrentIndentation . Value = previousIndentation ;
46+
3047 var end = TimeProvider . System . GetTimestamp ( ) ;
3148 var duration = TimeProvider . System . GetElapsedTime ( start , end ) . TotalMilliseconds ;
32- logger . LogInformation ( "-< End: {OperationDescription} (Took: {Duration:N}ms) >- " , operationDescription , duration ) ;
49+ logger . LogInformation ( "└─── End: {OperationDescription} (Took: {Duration:N}ms)" , operationDescription , duration ) ;
3350 } ) ;
3451 }
3552
0 commit comments