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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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}");
// }
//}
}
}
}