You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB
C#

using Hangfire.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.WMS.JobService
{
public class GlobalExceptionFilter : IServerFilter
{
public void OnPerforming(PerformingContext context)
{
// 不需要在这里做任何事情
}
public void OnPerformed(PerformedContext context)
{
Console.WriteLine(context.BackgroundJob);
// 当job执行完毕后检查是否有异常
//if (context.BackgroundJob.State == JobState.Failed)
//{
// // 获取异常信息
// var exception = context.Exception;
// if (exception != null)
// {
// // 处理异常,例如发送邮件、记录日志等
// // 这里可以使用依赖注入来处理异常如记录日志到Logging Service
// Console.WriteLine($"Job failed with exception: {exception.Message}");
// }
//}
}
}
}