Skip to content

Commit 01dbd76

Browse files
committed
fix: fix log
1 parent 4761043 commit 01dbd76

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using MongoDB.Bson;
2+
3+
namespace TelegramDownloader.Helpers
4+
{
5+
/// <summary>
6+
/// Custom type mapper for Guid to BsonValue conversion.
7+
/// Used by Serilog.Sinks.MongoDB to properly serialize Guid properties in logs.
8+
/// </summary>
9+
public class GuidTypeMapper : ICustomBsonTypeMapper
10+
{
11+
public bool TryMapToBsonValue(object value, out BsonValue bsonValue)
12+
{
13+
if (value is Guid guid)
14+
{
15+
bsonValue = new BsonString(guid.ToString());
16+
return true;
17+
}
18+
bsonValue = null!;
19+
return false;
20+
}
21+
}
22+
}

TelegramDownloader/Pages/InfoPage.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</p>
1919
<div class="version-badge">
2020
<i class="bi bi-tag"></i>
21-
v1.0.0
21+
v@AppVersion
2222
</div>
2323
</div>
2424

@@ -186,6 +186,7 @@
186186
private User user { get; set; }
187187
private DirectorySizeModel? dirSize { get; set; }
188188
private bool showFilesBreakdown { get; set; } = false;
189+
private string AppVersion => typeof(Program).Assembly.GetName().Version?.ToString() ?? "0.0.0";
189190

190191
private void ToggleFilesBreakdown()
191192
{

TelegramDownloader/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
using Microsoft.AspNetCore.StaticFiles;
77
using Microsoft.Extensions.FileProviders;
88
using MongoDB.Bson;
9-
using MongoDB.Bson.Serialization;
10-
using MongoDB.Bson.Serialization.Serializers;
119
using Serilog;
1210
using Serilog.Debugging;
1311
using Serilog.Events;
@@ -16,13 +14,14 @@
1614
using System.Net.Http;
1715
using TelegramDownloader.Data;
1816
using TelegramDownloader.Data.db;
17+
using TelegramDownloader.Helpers;
1918
using TelegramDownloader.Models;
2019
using TelegramDownloader.Services;
2120
using TelegramDownloader.Services.GitHub;
2221
using TL;
2322

24-
// Register Guid serializer for MongoDB to handle Guid types in log properties
25-
BsonSerializer.RegisterSerializer(new GuidSerializer(BsonType.String));
23+
// Register Guid type mapper for MongoDB to handle Guid types in log properties (used by Serilog sink)
24+
BsonTypeMapper.RegisterCustomTypeMapper(typeof(Guid), new GuidTypeMapper());
2625

2726
var extensionProvider = new FileExtensionContentTypeProvider();
2827
foreach(var mime in FileService.MIMETypesDictionary)

0 commit comments

Comments
 (0)