forked from ddrilling/AsbCloudServer
Work Добавлено больше информации в сообщение об ошибке.
This commit is contained in:
parent
fd5deaa5a2
commit
d99d1a27a1
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// делегат фоновой работы
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user