我有一个.NET核心2供电的API,我想添加到Hangfire。该项目已经使用NLog登录到MySQL数据库,并且运行良好,但是当我尝试设置和使用Hangfire时,会得到以下错误:
Method not found: 'Hangfire.Logging.ILog Hangfire.Logging.LogProvider.GetCurrentClassLogger()'.Hangfire仪表板可以工作,但是当我尝试像这样排列我的第一个任务时,我会遇到这个错误:
BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget"));我已经在:http://docs.hangfire.io/en/latest/configuration/configuring-logging.html阅读了Hangfire文档
上面写着:
从Hangfire 1.3.0开始,如果您的应用程序已经通过反射使用了以下库之一,则不需要做任何操作(这样Hangfire本身就不依赖于其中的任何一个库)。通过检查是否存在相应的类型,将自动选择日志实现,顺序如下。
这个列表包括NLog,所以很明显我做错了什么。
在我的csproj中有:
<PackageReference Include="Hangfire" Version="1.6.19" />
<PackageReference Include="Hangfire.MySqlStorage" Version="1.0.5" />
<PackageReference Include="MySql.Data" Version="8.0.11" />
<PackageReference Include="NLog" Version="4.5.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.5.2" />在Startup.cs和ConfigureServices中,我有:
services.AddHangfire(config => config.UseStorage(new MySqlStorage(appSettings.GetConnectionString("HangfireConnectionString"))));在Configure中,我有:
loggerFactory.AddNLog();
env.ConfigureNLog("nlog.config");
app.UseHangfireDashboard();
app.UseHangfireServer();我的nlog.config包含:
<target name="database" xsi:type="Database" dbProvider="MySql.Data.MySqlClient.MySqlConnection, MySql.Data" connectionString="server=localhost;Database=nlog;user id=root;password=;SslMode=none;">而且它可以在没有Hangfire的情况下登录到MySQL数据库,所以这似乎是可行的。
查看Nlog文档,请访问:
https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2
他们似乎将NLog添加到Program.cs中,而不是Startup.cs中,因此我也尝试了这种方法,但仍然会遇到相同的错误。
发布于 2018-04-20 12:24:39
看起来,Hangfire.MySqlStorage库是导致此错误的根本原因。在更改为Hangfire.MySql.Core之后,一切都很好,无需对NLog进行任何更改。
https://stackoverflow.com/questions/49933967
复制相似问题