- Notifications
You must be signed in to change notification settings - Fork0
Show jobs log messages on hangfire dashboard
License
emresebat/Hangfire.Dashboard.JobLogs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Show job logs on the dashboard.
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).
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
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;}}
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- C#100.0%