@@ -11,18 +11,27 @@ public CodeSampleService(
1111 _logger = logger ;
1212 _storage = storage ;
1313 if ( _logger . IsEnabled ( LogLevel . Trace ) )
14+ {
15+ _logger . LogTrace ( "Initializing options for {serviceName}..." ,
16+ nameof ( CodeSampleService < SampleOptions > ) ) ;
17+ }
18+ if ( _logger . IsEnabled ( LogLevel . Debug ) )
1419 {
1520 // Log LineRanges for each sample option
1621 foreach ( var sample in _options . Samples )
1722 {
18- _logger . LogTrace ( "SampleID : {sampleID},\n Description: {description},\n FilePath: {filePath},\n LineRanges: {lineRanges}",
23+ _logger . LogDebug ( " \t SampleID : {sampleID},\n Description: {description},\n FilePath: {filePath},\n LineRanges: {lineRanges}",
1924 sample . SampleID ,
2025 sample . Description ,
2126 sample . FilePath ,
2227 sample . LineRanges ) ;
2328
2429 }
2530 }
31+ else if ( _logger . IsEnabled ( LogLevel . Trace ) )
32+ {
33+ _logger . LogTrace ( "Gathered {count} Options" , _options . Samples . Length ) ;
34+ }
2635 }
2736
2837 private readonly IStorage _storage ;
@@ -46,8 +55,20 @@ public CodeSampleService(
4655 public async ValueTask < IImmutableList < string > > GetCodeSampleOptionsAsync ( CancellationToken ct = default )
4756 {
4857 await Task . Delay ( 1 ) ;
58+ _logger . LogTrace ( "Collecting available code sample options from appsettings.sampledata.json..." ) ;
4959 var sampleOptions = _options . Samples . Select ( sample => sample . SampleID ) . ToImmutableList ( ) ;
50- _logger . LogInformation ( "Options:\n {options}" , sampleOptions . JoinBy ( "," + Environment . NewLine ) ) ;
60+
61+ if ( _logger . IsEnabled ( LogLevel . Debug ) )
62+ {
63+ // Log available options
64+ _logger . LogDebug ( "Available Options:\n {options}" , sampleOptions . JoinBy ( "," + Environment . NewLine ) ) ;
65+ }
66+ else if ( _logger . IsEnabled ( LogLevel . Trace ) )
67+ {
68+ // Log available options
69+ _logger . LogTrace ( "Gathered {count} Options" , sampleOptions . Count ) ;
70+ }
71+
5172 return sampleOptions ;
5273 }
5374
@@ -57,7 +78,7 @@ public async ValueTask<string> GetCodeSampleAsync(string? sampleID, Cancellation
5778 {
5879 if ( _logger . IsEnabled ( LogLevel . Trace ) )
5980 {
60- _logger . LogTrace ( "SampleID: {sampleID},\n Description: {description},\n FilePath: {filePath},\n LineRanges: {lineRanges}" ,
81+ _logger . LogTrace ( "Fetching Storage Data for SampleID: {sampleID},\n Description: {description},\n FilePath: {filePath},\n LineRanges: {lineRanges}" ,
6182 sampleOption . SampleID ,
6283 sampleOption . Description ,
6384 sampleOption . FilePath ,
@@ -66,9 +87,8 @@ public async ValueTask<string> GetCodeSampleAsync(string? sampleID, Cancellation
6687
6788 return await _storage . ReadLinesFromPackageFile ( sampleOption . FilePath , sampleOption . LineRanges . Select ( lr => ( lr . Start , lr . End ) ) ) ;
6889 }
69-
7090
71- _logger . LogWarning ( "Code sample with ID {sampleID} not found" , sampleID ) ;
91+ _logger . LogError ( "Code sample with ID {sampleID} not found" , sampleID ) ;
7292 return string . Empty ;
7393 }
7494}
0 commit comments