Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core .NET核心:使用NLog的Hangfire设置_Asp.net Core_.net Core_Nlog_Hangfire - Fatal编程技术网

Asp.net core .NET核心:使用NLog的Hangfire设置

Asp.net core .NET核心:使用NLog的Hangfire设置,asp.net-core,.net-core,nlog,hangfire,Asp.net Core,.net Core,Nlog,Hangfire,我有一个.NETCore2驱动的API,我想添加Hangfire。该项目已经使用NLog登录到MySQL数据库,并且工作正常,但是当我尝试设置并使用Hangfire时,我得到以下错误: Method not found: 'Hangfire.Logging.ILog Hangfire.Logging.LogProvider.GetCurrentClassLogger()'. Hangfire仪表板工作正常,但我在尝试将我的第一份工作按如下方式排队时出错: BackgroundJob.Enque

我有一个.NETCore2驱动的API,我想添加Hangfire。该项目已经使用NLog登录到MySQL数据库,并且工作正常,但是当我尝试设置并使用Hangfire时,我得到以下错误:

Method not found: 'Hangfire.Logging.ILog Hangfire.Logging.LogProvider.GetCurrentClassLogger()'.
Hangfire仪表板工作正常,但我在尝试将我的第一份工作按如下方式排队时出错:

BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget"));
我已在以下位置阅读了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" />
services.AddHangfire(config => config.UseStorage(new MySqlStorage(appSettings.GetConnectionString("HangfireConnectionString"))));
loggerFactory.AddNLog();
env.ConfigureNLog("nlog.config");

app.UseHangfireDashboard();
app.UseHangfireServer();
Configure
中,我有:

<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" />
services.AddHangfire(config => config.UseStorage(new MySqlStorage(appSettings.GetConnectionString("HangfireConnectionString"))));
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文档,网址为:


他们似乎在
Program.cs
中添加了NLog,而不是
Startup.cs
,因此我也尝试了这种方法,但仍然得到了相同的错误

看起来像是
Hangfire。MySqlStorage
库是此错误的根本原因。在更改为
Hangfire.MySql.Core之后,一切都很好,没有对NLog进行任何更改