-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(hangfire): #29 log job start and finish
- Loading branch information
Showing
6 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...Plugins/Jobs/Hangfire/src/PiBox.Plugins.Jobs.Hangfire/Attributes/LogJobExecutionFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Hangfire.Common; | ||
using Hangfire.Server; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace PiBox.Plugins.Jobs.Hangfire.Attributes | ||
{ | ||
public class LogJobExecutionFilter : JobFilterAttribute, | ||
IServerFilter | ||
{ | ||
private readonly ILoggerFactory _loggerFactory; | ||
|
||
public LogJobExecutionFilter(ILoggerFactory loggerFactory) | ||
{ | ||
_loggerFactory = loggerFactory; | ||
} | ||
public void OnPerforming(PerformingContext context) | ||
{ | ||
_loggerFactory.CreateLogger(context.BackgroundJob.Job.Type) | ||
.LogInformation("Job with id {JobId} started executing", context.BackgroundJob.Id); | ||
} | ||
|
||
public void OnPerformed(PerformedContext context) | ||
{ | ||
_loggerFactory.CreateLogger(context.BackgroundJob.Job.Type) | ||
.LogInformation("Job with id {JobId} finished executing", context.BackgroundJob.Id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters