我在这里创建了一个独立的问题复制:https://github.com/GuerrillaCoder/HangfireLoggingTest
使用的版本:
<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.12" />
<PackageReference Include="Hangfire.Console" Version="1.4.2" />
<PackageReference Include="Hangfire.Core" Version="1.7.12" />
<PackageReference Include="Hangfire.MemoryStorage.Core" Version="1.4.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" />
</ItemGroup>问题:
Hangfire从不将任何东西写入日志,这使得调试任务延迟或失败的问题变得非常困难。
我相信我已经正确地遵循了指令,并将LogLevel设置为Trace,但是除了直接向Nlog记录器发送消息之外,没有任何东西被写入日志。
再生产步骤
https://github.com/GuerrillaCoder/HangfireLoggingTest
上写任何日志消息
发布于 2020-08-03 18:44:55
尝试像这样更新ConfigureServices:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Register NLog as LoggingProvider for Microsoft ILogger
services.AddLogging(builder => {
loggingBuilder.ClearProviders();
loggingBuilder.AddNLog();
});
services.AddControllersWithViews();
// Only needed for NetFramework with LibLog. NetCore uses Microsoft ILogger
// GlobalConfiguration.Configuration.UseNLogLogProvider();
services.AddHangfire((isp, config) =>
{
config.UseMemoryStorage();
config.UseConsole(); // https://www.nuget.org/packages/Hangfire.Console/
});
}另见:https://docs.hangfire.io/en/latest/configuration/configuring-logging.html
https://stackoverflow.com/questions/63229315
复制相似问题