From d99d1a27a12bea36a65593851d403b923b02f178 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 12 Oct 2023 12:45:19 +0500 Subject: [PATCH] =?UTF-8?q?Work=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BE=D0=B1=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/Background/Work.cs | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/AsbCloudInfrastructure/Background/Work.cs b/AsbCloudInfrastructure/Background/Work.cs index 9372343b..eba7df66 100644 --- a/AsbCloudInfrastructure/Background/Work.cs +++ b/AsbCloudInfrastructure/Background/Work.cs @@ -1,5 +1,6 @@ using AsbCloudApp.Data; using System; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -74,7 +75,8 @@ public abstract class Work : BackgroundWorkDto } catch (Exception exception) { - SetLastError(exception.Message); + var message = FormatExceptionMessage(exception); + SetLastError(message); if (OnErrorAsync is not null) { var task = Task.Run( @@ -86,6 +88,31 @@ public abstract class Work : BackgroundWorkDto return false; } + private static string FormatExceptionMessage(Exception exception) + { + var firstException = FirstException(exception); + var message = new StringBuilder(); + if (firstException != exception) + { + message.Append("top exception:"); + message.AppendLine(exception.Message); + + message.Append("inner exception:"); + message.AppendLine(firstException.Message); + } + else + message.AppendLine(firstException.Message); + message.AppendLine(exception.StackTrace); + return message.ToString(); + } + + private static Exception FirstException(Exception exception) + { + if (exception.InnerException is not null) + return FirstException(exception.InnerException); + return exception; + } + /// /// делегат фоновой работы ///