Improved layout of scheduled healthcheck result logging

This commit is contained in:
AndyButland
2017-06-05 10:14:47 +02:00
parent 0366fa73c3
commit 474dcf0779
3 changed files with 45 additions and 11 deletions

View File

@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Logging;
namespace Umbraco.Web.HealthCheck
{
public class HealthCheckResults
{
private readonly Dictionary<string, IEnumerable<HealthCheckStatus>> _results;
public HealthCheckResults(IEnumerable<HealthCheck> checks)
{
_results = checks.ToDictionary(t => t.Name, t => t.GetStatus());
}
public void LogResults()
{
LogHelper.Info<HealthCheckResults>("Scheduled health check results:");
foreach (var result in _results)
{
var checkName = result.Key;
var checkResults = result.Value;
var checkIsSuccess = result.Value.All(x => x.ResultType == StatusResultType.Success);
if (checkIsSuccess)
{
LogHelper.Info<HealthCheckResults>(string.Format(" Checks for '{0}' all completed succesfully.", checkName));
}
else
{
LogHelper.Warn<HealthCheckResults>(string.Format(" Checks for '{0}' completed with errors.", checkName));
}
foreach (var checkResult in checkResults)
{
LogHelper.Info<HealthCheckResults>(string.Format(" Result: {0}, Message: '{1}'", checkResult.ResultType, checkResult.Message));
}
}
}
}
}

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
@@ -50,14 +52,8 @@ namespace Umbraco.Web.Scheduling
var checks = _healthCheckResolver.HealthChecks
.Where(x => disabledCheckIds.Contains(x.Id) == false);
var sb = new StringBuilder();
foreach (var check in checks)
{
// TODO: get all sub-checks, not just first
var status = check.GetStatus().First();
sb.AppendFormat(" - Check {0} returned {1} with message {2}.", check.Name, status.ResultType, status.Message);
sb.AppendLine();
}
var results = new HealthCheckResults(checks);
results.LogResults();
// TODO: get email address and send
if (!string.IsNullOrEmpty(healthCheckConfig.NotificationSettings.RecipientEmail))
@@ -70,9 +66,6 @@ namespace Umbraco.Web.Scheduling
{
}
LogHelper.Info<HealthCheckNotifier>("Health check results:");
LogHelper.Info<HealthCheckNotifier>(sb.ToString());
}
return true; // repeat

View File

@@ -336,6 +336,7 @@
<Compile Include="HealthCheck\HealthCheckGroup.cs" />
<Compile Include="HealthCheck\HealthCheckResolver.cs" />
<Compile Include="HealthCheck\HealthCheck.cs" />
<Compile Include="HealthCheck\HealthCheckResults.cs" />
<Compile Include="HealthCheck\HealthCheckStatus.cs" />
<Compile Include="HealthCheck\Checks\Security\HttpsCheck.cs" />
<Compile Include="HealthCheck\IHealthCheckResolver.cs" />