Skip to content

Commit 4169c45

Browse files
authored
feat(ErrorLogger): redesign ErrorLogger component (#7558)
* refactor: 更新日志逻辑 * test: 更新单元测试 * doc: 更新示例 * test: 更新单元测试 * feat: 增加 ErrorRender 组件 * doc: 文档格式化 * doc: 文档格式化 * refactor: 增加异常日志等逻辑 * test: 更新单元测试 * refactor: 增加 ToastTitle 本地化位置 * doc: 更新注释 * feat: 增加日志开关逻辑 * refactor: 重构异常处理机制 * test: 更新单元测试 * refactor: 重构代码 * test: 排除单元测试 * doc: 更新示例 * refactor: 重构代码 * test: 更新单元测试 * test: 支持弹窗显示错误信息 * test: 增加单元测试 * doc: 更新示例 * doc: 增加排序 * chore: 重构代码 * doc: 更新注释 * chore: bump version 10.2.2
1 parent c237053 commit 4169c45

23 files changed

+324
-378
lines changed

src/BootstrapBlazor.Server/Components/Samples/GlobalException.razor

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@
5757
"DetailedErrors": true
5858
}</Pre>
5959

60-
<DemoBlock Title="@Localizer["Block1Title"]" Introduction="@Localizer["Block1Intro"]" Name="Normal">
60+
<DemoBlock Title="@Localizer["NormalTitle"]" Introduction="@Localizer["NormalIntro"]" Name="Normal">
6161
<section ignore>@((MarkupString)Localizer["ExceptionTestIntroduce"].Value)</section>
62-
<Button Icon="fa-solid fa-font-awesome" Text="@Localizer["ButtonText"]" OnClick="OnClick" />
62+
<Button Icon="fa-solid fa-font-awesome" Text="@Localizer["Button1Text"]" OnClick="OnClick" />
63+
<button class="btn btn-primary" @onclick="OnClick">
64+
<i class="fa-solid fa-font-awesome"></i>
65+
<span>@Localizer["Button2Text"]</span>
66+
</button>
6367
</DemoBlock>
6468

65-
<DemoBlock Title="@Localizer["Block2Title"]" Introduction="@Localizer["Block2Intro"]" Name="Swal">
69+
<DemoBlock Title="@Localizer["OnErrorHandleTitle"]" Introduction="@Localizer["OnErrorHandleIntro"]" Name="Swal">
6670
<ErrorLogger OnErrorHandleAsync="OnErrorHandleAsync">
6771
<Button Icon="fa-solid fa-font-awesome" Text="@Localizer["ButtonText"]" OnClick="OnClick" />
6872
</ErrorLogger>

src/BootstrapBlazor.Server/Components/Samples/GlobalException.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"Type": "Type"
2121
},
2222
"BootstrapBlazor.Server.Components.Components.AttributeTable": {
23-
"Obsolete": "Obsolete",
2423
"AutoGenerateColumns": "Automatically generated",
24+
"Obsolete": "Obsolete",
2525
"Total": "Total"
2626
},
2727
"BootstrapBlazor.Server.Components.Components.CultureChooser": {
@@ -2407,17 +2407,19 @@
24072407
"WatchPositionResultSuccess": "Call WatchPosition success"
24082408
},
24092409
"BootstrapBlazor.Server.Components.Samples.GlobalException": {
2410-
"Block1Intro": "This function is to obtain the component instance through the cascade parameter and use its function",
2411-
"Block1Title": "Test",
2412-
"Block2Intro": "Set custom exception handling logic by setting <code>OnErrorHandleAsync</code> callback method",
2413-
"Block2Title": "OnErrorHandleAsync",
2414-
"ButtonText": "test",
2410+
"Button1Text": "Test(Component)",
2411+
"Button2Text": "Test(HtmlElement)",
2412+
"ButtonText": "Test",
24152413
"DialogIntro": "Click the button to pop up a pop-up window. The button in the pop-up window triggers an exception and the error is displayed in the pop-up window",
24162414
"DialogText": "Popup",
24172415
"DialogTitle": "In Dialog",
24182416
"ExceptionTestIntroduce": "In this example code, an error code that divides by zero is written. Because <code>try/catch</code> is used to capture the exception, the error message is displayed in the console below",
24192417
"H1": "Instructions",
24202418
"Introduce": "Added component <code>ErrorLogger</code> Through this component, global logs and exceptions can be output uniformly; currently, the <code>Blazor</code> framework does not provide a <code>MVC</code> like <b>Global exception</b> The overall solution",
2419+
"NormalIntro": "This function is to obtain the component instance through the cascade parameter and use its function",
2420+
"NormalTitle": "Test",
2421+
"OnErrorHandleIntro": "By setting the <code>OnErrorHandleAsync</code> parameter of <code>ErrorLogger</code>, you can customize the use of the <code>Swal</code> pop-up to display exception information.",
2422+
"OnErrorHandleTitle": "OnErrorHandleAsync",
24212423
"PageErrorIntro": "Click the button to navigate to the page where the error occurred during the page life cycle. The error is displayed on the current page and does not affect the menu and the overall page layout.",
24222424
"PageErrorTitle": "Page",
24232425
"Step1": "1. Add <code>AddLogging</code> to the <code>Startup</code> file to enable the <code>net core</code> system log function",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"Type": "类型"
2121
},
2222
"BootstrapBlazor.Server.Components.Components.AttributeTable": {
23-
"Obsolete": "已弃用",
2423
"AutoGenerateColumns": "自动生成",
24+
"Obsolete": "已弃用",
2525
"Total": "合计"
2626
},
2727
"BootstrapBlazor.Server.Components.Components.CultureChooser": {
@@ -2407,17 +2407,19 @@
24072407
"WatchPositionResultSuccess": "调用 WatchPosition 成功"
24082408
},
24092409
"BootstrapBlazor.Server.Components.Samples.GlobalException": {
2410-
"Block1Intro": "本功能是通过代码产生异常信息,由全局捕获组件统一处理",
2411-
"Block1Title": "测试",
2412-
"Block2Intro": "通过设置 <code>OnErrorHandleAsync</code> 回调方法,设置自定义异常处理逻辑",
2413-
"Block2Title": "自定义错误处理",
2410+
"Button1Text": "测试(组件)",
2411+
"Button2Text": "测试(原生)",
24142412
"ButtonText": "测试",
24152413
"DialogIntro": "点击按钮弹出弹窗,弹窗内按钮触发异常,错误显示在弹窗内",
24162414
"DialogText": "弹窗",
24172415
"DialogTitle": "弹窗中异常捕获",
24182416
"ExceptionTestIntroduce": "本例代码中写了一个除以零的错误代码,并且未使用 <code>try/catch</code> 对异常进行捕获,系统并不会崩溃导致不可用,<ul class='ul-demo'><li><code>Debug</code> 模式下会显示错误的 <b>描述信息</b> 与 <b>堆栈信息</b></li><li><code>Release</code> 模式下默认使用 <code>Toast</code> 进行弹窗提示</li></ul>",
24192417
"H1": "使用方法",
24202418
"Introduce": "<p>增加组件 <code>ErrorLogger</code> 通过本组件可以对全局的日志、异常进行统一输出;目前由于 <code>Blazor</code> 框架并未提供一个类似 <code>MVC</code> 的 <b>全局异常</b> 整体解决方案;通过使用 <code>ErrorLogger</code> 组件 <b>无需任何额外代码</b> 即可进行全局异常捕获与处理</p>",
2419+
"NormalIntro": "本功能是通过代码产生异常信息,由全局捕获组件统一处理",
2420+
"NormalTitle": "测试",
2421+
"OnErrorHandleIntro": "通过设置 <code>ErrorLogger</code> 参数 <code>OnErrorHandleAsync</code> 自定义使用 <code>Swal</code> 弹窗显示异常信息",
2422+
"OnErrorHandleTitle": "自定义错误处理",
24212423
"PageErrorIntro": "点击按钮导航到页面生命周期内出错的页面,错误显示在当前页面,不影响菜单以及整体页面布局",
24222424
"PageErrorTitle": "页面异常捕获",
24232425
"Step1": "1. <code>Startup</code> 文件中增加 <code>AddLogging</code> 开启 <code>net core</code> 系统日志功能,支持其他第三方 <code>Logger</code> 组件",

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.2.2-beta02</Version>
4+
<Version>10.2.2</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

0 commit comments

Comments
 (0)