将Catch块中 打印Log的全部替换为NotificationHelper.ShowError

This commit is contained in:
2025-07-06 15:15:38 +08:00
parent 533a49d47b
commit b0874a4f02
8 changed files with 175 additions and 31 deletions

View File

@@ -77,8 +77,7 @@ public partial class DevicesViewModel : ViewModelBase
}
catch (Exception e)
{
NotificationHelper.ShowMessage($"添加设备的过程中发生错误:{e.Message}", NotificationType.Error);
_logger.LogError($"添加设备的过程中发生错误:{e}");
NotificationHelper.ShowError($"添加设备的过程中发生错误:{e.Message}", e);
}
}
@@ -112,8 +111,7 @@ public partial class DevicesViewModel : ViewModelBase
}
catch (Exception e)
{
NotificationHelper.ShowMessage($"删除设备的过程中发生错误:{e.Message}", NotificationType.Error);
_logger.LogError($"删除设备的过程中发生错误:{e}");
NotificationHelper.ShowError($"删除设备的过程中发生错误:{e.Message}", e);
}
}
@@ -146,8 +144,7 @@ public partial class DevicesViewModel : ViewModelBase
}
catch (Exception e)
{
NotificationHelper.ShowMessage($"编辑设备的过程中发生错误:{e.Message}", NotificationType.Error);
_logger.LogError($"编辑设备的过程中发生错误:{e}");
NotificationHelper.ShowError($"编辑设备的过程中发生错误:{e.Message}", e);
}
}
}

View File

@@ -134,9 +134,7 @@ public partial class MainViewModel : ViewModelBase
catch (Exception e)
{
await db.RollbackTranAsync();
// 捕获并记录所有未预料的异常
_logger.LogError($"添加变量表时出现了未预期的错误:{e}");
NotificationHelper.ShowMessage($"添加变量表时出现了错误:{e.Message}", NotificationType.Error);
NotificationHelper.ShowError($"添加变量表时出现了错误:{e.Message}", e);
}
}
@@ -198,8 +196,7 @@ public partial class MainViewModel : ViewModelBase
}
catch (Exception e)
{
_logger.LogError($"菜单切换出现了错误:{e}");
NotificationHelper.ShowMessage($"菜单切换是出现了错误:{e.Message}", NotificationType.Error);
NotificationHelper.ShowError($"菜单切换出现了错误:{e.Message}", e);
}
}
}

View File

@@ -70,8 +70,7 @@ public partial class MqttsViewModel : ViewModelBase
}
catch (Exception e)
{
NotificationHelper.ShowMessage($"添加MQTT的过程中发生错误{e.Message}", NotificationType.Error);
_logger.LogError($"添加MQTT的过程中发生错误{e}");
NotificationHelper.ShowError($"添加MQTT的过程中发生错误{e.Message}", e);
}
}
@@ -98,8 +97,7 @@ public partial class MqttsViewModel : ViewModelBase
}
catch (Exception e)
{
NotificationHelper.ShowMessage($"删除MQTT的过程中发生错误{e.Message}", NotificationType.Error);
_logger.LogError($"删除MQTT的过程中发生错误{e}");
NotificationHelper.ShowError($"删除MQTT的过程中发生错误{e.Message}", e);
}
}
@@ -123,8 +121,7 @@ public partial class MqttsViewModel : ViewModelBase
}
catch (Exception e)
{
NotificationHelper.ShowMessage($"编辑MQTT的过程中发生错误{e.Message}", NotificationType.Error);
_logger.LogError($"编辑MQTT的过程中发生错误{e}");
NotificationHelper.ShowError($"编辑MQTT的过程中发生错误{e.Message}", e);
}
}

View File

@@ -140,9 +140,7 @@ partial class VariableTableViewModel : ViewModelBase
}
catch (Exception e)
{
string msg = $"编辑变量的过程中发生了不可预期的错误:";
Logger.Error(msg + e);
NotificationHelper.ShowMessage(msg + e.Message, NotificationType.Error);
NotificationHelper.ShowError($"编辑变量的过程中发生了不可预期的错误:{e.Message}", e);
}
}
@@ -182,9 +180,7 @@ partial class VariableTableViewModel : ViewModelBase
}
catch (Exception e)
{
string msg = $"从TIA导入变量的过程中发生了不可预期的错误";
Logger.Error(msg + e);
NotificationHelper.ShowMessage(msg + e.Message, NotificationType.Error);
NotificationHelper.ShowError($"从TIA导入变量的过程中发生了不可预期的错误{e.Message}", e);
}
@@ -211,9 +207,7 @@ partial class VariableTableViewModel : ViewModelBase
}
catch (Exception e)
{
string msg = $"添加变量的过程中发生了不可预期的错误:";
Logger.Error(msg + e);
NotificationHelper.ShowMessage(msg + e.Message, NotificationType.Error);
NotificationHelper.ShowError($"添加变量的过程中发生了不可预期的错误:{e.Message}", e);
}
}
@@ -253,9 +247,7 @@ partial class VariableTableViewModel : ViewModelBase
}
catch (Exception e)
{
string msg = $"删除变量的过程中发生了不可预期的错误:";
Logger.Error(msg + e);
NotificationHelper.ShowMessage(msg + e.Message, NotificationType.Error);
NotificationHelper.ShowError($"删除变量的过程中发生了不可预期的错误:{e.Message}", e);
}
}
@@ -319,8 +311,7 @@ partial class VariableTableViewModel : ViewModelBase
}
catch (Exception ex)
{
Logger.Error(ex, "添加MQTT服务器到变量时发生错误。");
NotificationHelper.ShowMessage($"添加MQTT服务器失败: {ex.Message}", NotificationType.Error);
NotificationHelper.ShowError($"添加MQTT服务器失败: {ex.Message}", ex);
}
}