Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Show jobs log messages on hangfire dashboard

License

NotificationsYou must be signed in to change notification settings

meriturva/Hangfire.Dashboard.JobLogs

Repository files navigation

Latest version

Show job logs on the dashboard.

image

The project takes advantage of the integration with NLog thanks toNLog.HangfireJobLogsTarget.

Note: the project is really simple but it is a good starting point (in my opinion).

Installation

Hangfire.Dashboard.JobLogs is available as a NuGet package. You can install it using the NuGet Package Console window:

PM> Install-Package Bonura.Hangfire.Dashboard.JobLogs

Configuration

NLog configuration withHangfireJobLogs target and layout with${hangfire-decorator} (mandatory).

"NLog": {"extensions": [    {"assembly":"NLog.HangfireJobLogsTarget"    }  ],"default-wrapper": {"type":"AsyncWrapper","overflowAction":"Block"  },"targets": {"hangfire_dashboard": {"layout":"${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=toString}${hangfire-decorator}","type":"HangfireJobLogs"    }  },"rules": {"hangfire": {"logger":"Sample.Jobs.*","minLevel":"Info","writeTo":"hangfire_dashboard"    }  }}

Services configuration:

// Add hangfire context servicesbuilder.Services.AddHangfirePerformContextAccessor();// Add Hangfire services.builder.Services.AddHangfire((serviceProvider,config)=>{// Add filter to handle PerformContextAccessorconfig.UsePerformContextAccessorFilter(serviceProvider);// Add a storageconfig.UseInMemoryStorage();// Add dashboard jobLogsconfig.UseDashboardJobLogs();});// Add the processing server as IHostedServicebuilder.Services.AddHangfireServer();

Job usingILogger (Microsoft.Extensions.Logging):

publicclassSimpleJob{privateILogger<SimpleJob>_logger;publicSimpleJob(ILogger<SimpleJob>logger){_logger=logger;}publicasyncTaskDoJobAsync(){_logger.LogInformation("Log message");awaitTask.CompletedTask;}}

How it works

Basically, a log message produced by a hangfire job is captured by NLogNLog.HangfireJobLogsTarget. Thanks to${hangfire-decorator} andPerformContextAccessor log messages are sent to Hangfire storage.Finally, log messages are shown on the detail page thanks to a simpleJobDetailsRenderer.

See sample project:

https://github.com/meriturva/Hangfire.Dashboard.JobLogs/tree/main/Sample

About

Show jobs log messages on hangfire dashboard

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp