Skip to content

Commit 2a5ee54

Browse files
committed
feat: 增加日志逻辑
1 parent d0db0be commit 2a5ee54

3 files changed

Lines changed: 73 additions & 1 deletion

File tree

src/extensions/BootstrapBlazor.Socket/BootstrapBlazor.Socket.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@
99
<Description>BootstrapBlazor extensions of Socket</Description>
1010
</PropertyGroup>
1111

12+
<PropertyGroup>
13+
<NET8Version>8.0.*</NET8Version>
14+
<NET9Version>9.0.*</NET9Version>
15+
</PropertyGroup>
16+
17+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
18+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(NET8Version)" />
19+
</ItemGroup>
20+
21+
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
22+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(NET8Version)" />
23+
</ItemGroup>
24+
25+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
26+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(NET9Version)" />
27+
</ItemGroup>
28+
29+
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
30+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(NET9Version)" />
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
</ItemGroup>
35+
1236
<ItemGroup>
1337
<Using Include="BootstrapBlazor.DataAdapters" />
1438
<Using Include="BootstrapBlazor.DataHandlers" />

src/extensions/BootstrapBlazor.Socket/DataConverter/DataConverter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

5+
using BootstrapBlazor.Components;
56
using System.Reflection;
67

78
namespace BootstrapBlazor.DataConverters;
@@ -38,7 +39,10 @@ public virtual bool TryConvertTo(ReadOnlyMemory<byte> data, [NotNullWhen(true)]
3839
ret = true;
3940
}
4041
}
41-
catch { }
42+
catch (Exception ex)
43+
{
44+
SocketLogging.LogError(ex, "DataConverter TryConvertTo failed");
45+
}
4246

4347
return ret;
4448
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
using Microsoft.Extensions.Logging;
6+
7+
namespace BootstrapBlazor.Components;
8+
9+
/// <summary>
10+
/// Socket 日志记录类
11+
/// </summary>
12+
public static class SocketLogging
13+
{
14+
private static ILogger? _logger;
15+
private static bool _inited;
16+
17+
/// <summary>
18+
/// 返回 是否已经初始化
19+
/// </summary>
20+
public static bool Inited => _inited;
21+
22+
/// <summary>
23+
/// 初始化 ILogger 实例
24+
/// </summary>
25+
/// <param name="logger"></param>
26+
public static void Init(ILogger logger)
27+
{
28+
_inited = true;
29+
_logger = logger;
30+
}
31+
32+
/// <summary>
33+
///
34+
/// </summary>
35+
/// <param name="message"></param>
36+
public static void LogError(string message) => _logger?.LogError(message);
37+
38+
/// <summary>
39+
///
40+
/// </summary>
41+
/// <param name="ex"></param>
42+
/// <param name="message"></param>
43+
public static void LogError(Exception ex, string? message) => _logger?.LogError(ex, message);
44+
}

0 commit comments

Comments
 (0)