Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions Hangfire.Dashboard.JobLogs/GlobalConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Linq;
using System.Runtime.Caching;

namespace Hangfire.Dashboard.JobLogs
{
Expand All @@ -7,6 +9,7 @@ namespace Hangfire.Dashboard.JobLogs
/// </summary>
public static class GlobalConfigurationExtensions
{
static readonly ObjectCache renderedJobs = MemoryCache.Default;
/// <summary>
/// Configures Hangfire to use JobLogs.
/// </summary>
Expand All @@ -15,10 +18,27 @@ public static IGlobalConfiguration UseDashboardJobLogs(this IGlobalConfiguration
{
configuration.UseJobDetailsRenderer(100, dto =>
{
// avoid multiple renders for the same JobId
if (renderedJobs.Get(dto.JobId) != null)
{
return new NonEscapedString(string.Empty);
}

var jobStorageConnection = JobStorage.Current.GetConnection();
var logString = "No Logs Found";
var logsMessages = jobStorageConnection.GetAllEntriesFromHash($"joblogs-jobId:{dto.JobId}");

var logString = string.Join("<br>", logsMessages.Select(kvp => kvp.Value));
if (logsMessages != null)
{
logString = string.Join("<br>", logsMessages.Where(kvp => kvp.Value != null).Select(kvp => kvp.Value));
}

// cache rendered JobId
var policy = new CacheItemPolicy
{
AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddSeconds(1))
};
renderedJobs.Set(dto.JobId, true, policy);

return new NonEscapedString($"<h3>Log messages</h3>" +
$"<div class=\"state-card \"><div class=\"state-card-body\">{logString}</div></div>" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<ItemGroup>
<PackageReference Include="Hangfire.Core" Version="1.8.5" />
<PackageReference Include="System.Runtime.Caching" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down