【发布时间】:2020-01-16 09:39:17
【问题描述】:
我已经为我的 ASP.NET 项目成功设置了hangfire,即在我的数据库中创建了 11 个 Hangfire 表。我在我项目的Global.asax 的Application_Start() 中尝试了以下命令:
namespace myAPI
{
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start(
{
System.Diagnostics.Debug.WriteLine("Recurring job will be set up.");
RecurringJob.AddOrUpdate(
"some-id",
() => System.Diagnostics.Debug.WriteLine("Job instance started at " +
DateTime.Now)),
"*/2 * * * 1-5");
}
}
}
可悲的是,在 Visual Studio 的窗口中 Output > Debug 我只看到 Reccuring job will be set up. 之后就什么也没有了。但是,SELECT * FROM [myContext].[HangFire].[Set] 显示给我
Key Score Value ExpireAt
recurring-jobs 1579116240 some-id NULL
到目前为止一切顺利,这意味着工作确实已经建立。
但是我如何在每次执行 RecurringJob 时在我的数据库中记录?我是否正确假设 Hangfire 不会开箱即用地执行此操作,并且我必须自己在箭头功能中记录它吗?还是有更优雅的方式?
另外一个问题:为什么我没有看到System.Diagnostics.Debug.WriteLine 的任何输出在我的经常性工作中?
参考文献
【问题讨论】:
标签: c# asp.net logging hangfire