Skip to content

Commit 2d2a89d

Browse files
committed
chore: Added some more logging to Service since it caused problems in Serialization in the past
1 parent 191e201 commit 2d2a89d

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

src/DevTKSS.Uno.Samples.MvuxGallery/Models/CodeSamples/CodeSampleService.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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},\nDescription: {description},\nFilePath: {filePath},\nLineRanges: {lineRanges}",
23+
_logger.LogDebug("\tSampleID: {sampleID},\nDescription: {description},\nFilePath: {filePath},\nLineRanges: {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},\nDescription: {description},\nFilePath: {filePath},\nLineRanges: {lineRanges}",
81+
_logger.LogTrace("Fetching Storage Data for SampleID: {sampleID},\nDescription: {description},\nFilePath: {filePath},\nLineRanges: {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
}

src/DevTKSS.Uno.Samples.MvuxGallery/Models/GalleryImages/GalleryImageService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
namespace DevTKSS.Uno.Samples.MvuxGallery.Models.GalleryImages;
2-
[Bindable]
32
public partial class GalleryImageService : IGalleryImageService
43
{
54
private readonly ILocalizationService _localizationService;
65
private readonly IStringLocalizer _stringlocalizer;
6+
private readonly ILogger<GalleryImageService> _logger;
77
public GalleryImageService(
88
ILocalizationService localizationService,
9-
IStringLocalizer _stringLocalizer)
9+
IStringLocalizer _stringLocalizer,
10+
ILogger<GalleryImageService> logger)
1011
{
1112
_localizationService = localizationService;
1213
_stringlocalizer = _stringLocalizer;
14+
_logger = logger;
1315
}
1416

1517
public async ValueTask<IImmutableList<GalleryImageModel>> GetGalleryImagesWithReswAsync(CancellationToken ct)
@@ -19,6 +21,7 @@ public async ValueTask<IImmutableList<GalleryImageModel>> GetGalleryImagesWithRe
1921
public async ValueTask<IImmutableList<GalleryImageModel>> GetGalleryImagesWithoutReswAsync(CancellationToken ct)
2022
{
2123
string cultureString = _localizationService.CurrentCulture.TwoLetterISOLanguageName;
24+
_logger.LogTrace("Trying to get GalleryImages for Culture: {culture}", cultureString);
2225
var galleryImages = cultureString switch
2326
{
2427
"de" => await GetDEGalleryImagesAsync(ct),
@@ -33,7 +36,9 @@ public async ValueTask<IImmutableList<GalleryImageModel>> GetGalleryImagesWithou
3336
#region With resw
3437
private async ValueTask<IImmutableList<GalleryImageModel>> GetGalleryImagesAsync(CancellationToken ct)
3538
{
39+
// Simulate a delay to mimic data fetching
3640
await Task.Delay(TimeSpan.FromSeconds(2), ct);
41+
_logger.LogTrace("Trying to get GalleryImages from Resw");
3742
var galleryImages = new GalleryImageModel[]
3843
{
3944
new GalleryImageModel(
@@ -72,6 +77,7 @@ private async ValueTask<IImmutableList<GalleryImageModel>> GetDEGalleryImagesAsy
7277
{
7378
// Simulate a delay to mimic data fetching
7479
await Task.Delay(TimeSpan.FromSeconds(2),ct);
80+
_logger.LogTrace("Creating DE GalleryImages without resw");
7581
var galleryImages = new GalleryImageModel[]
7682
{
7783
new GalleryImageModel(
@@ -108,6 +114,7 @@ private async ValueTask<IImmutableList<GalleryImageModel>> GetENGalleryImagesAsy
108114
{
109115
// Simulate a delay to mimic data fetching
110116
await Task.Delay(TimeSpan.FromSeconds(2), ct);
117+
_logger.LogTrace("Creating EN GalleryImages without resw");
111118
var galleryImages = new GalleryImageModel[]
112119
{
113120
new GalleryImageModel(

0 commit comments

Comments
 (0)