Skip to content

Commit 4a5471c

Browse files
The most significant changes involve the addition of new namespaces to the DependencyInjection.cs file and the introduction of a new parameter to the AddKenticoHealthChecks method. This new parameter, useEventLogPublisher, is used to conditionally configure the HealthCheckPublisherOptions and register a singleton of type IHealthCheckPublisher with the KenticoEventLogHealthCheckPublisher implementation. The AddKenticoHealthChecks method now also includes the configuration for the KenticoEventLogHealthCheckPublisher if useEventLogPublisher is true.
Changes: 1. The `Microsoft.Extensions.Diagnostics.HealthChecks` and `XperienceCommunity.AspNetCore.HealthChecks.Publishers` namespaces have been added to the `DependencyInjection.cs` file. This change allows the use of health check diagnostics and publishers in the code. 2. A new parameter `useEventLogPublisher` of type `bool` has been added to the `AddKenticoHealthChecks` method in the `XperienceCommunity.AspNetCore.HealthChecks` namespace. This parameter is used to determine whether to use the `KenticoEventLogHealthCheckPublisher`. 3. A conditional statement has been added inside the `AddKenticoHealthChecks` method to check if `useEventLogPublisher` is true. If it is, the `HealthCheckPublisherOptions` are configured with a delay of 2 seconds and a predicate that checks if the health check tags contain 'Kentico'. This change allows for the configuration of health check options based on the `useEventLogPublisher` parameter. 4. A singleton of type `IHealthCheckPublisher` is registered with the `KenticoEventLogHealthCheckPublisher` implementation if `useEventLogPublisher` is true. This change ensures that the `KenticoEventLogHealthCheckPublisher` is used when `useEventLogPublisher` is true. 5. The `AddKenticoHealthChecks` method now returns an `IHealthChecksBuilder` instance with the same health checks as before, but also includes the configuration for the `KenticoEventLogHealthCheckPublisher` if `useEventLogPublisher` is true. This change ensures that the health checks include the `KenticoEventLogHealthCheckPublisher` configuration when `useEventLogPublisher` is true.
1 parent 7bb7ecb commit 4a5471c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/XperienceCommunity.AspNetCore.HealthChecks/DependencyInjection.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Diagnostics.HealthChecks;
23
using XperienceCommunity.AspNetCore.HealthChecks.HealthChecks;
4+
using XperienceCommunity.AspNetCore.HealthChecks.Publishers;
35

46
namespace XperienceCommunity.AspNetCore.HealthChecks
57
{
@@ -15,9 +17,21 @@ public static class DependencyInjection
1517
/// Adds Kentico Specific Health Checks
1618
/// </summary>
1719
/// <param name="services">The <see cref="IServiceCollection"/> to add the health checks to.</param>
20+
/// <param name="useEventLogPublisher">Optionally Use the Event Log Publisher.</param>
1821
/// <returns>The <see cref="IHealthChecksBuilder"/> instance.</returns>
19-
public static IHealthChecksBuilder AddKenticoHealthChecks(this IServiceCollection services)
20-
{
22+
public static IHealthChecksBuilder AddKenticoHealthChecks(this IServiceCollection services, bool useEventLogPublisher)
23+
{
24+
if (useEventLogPublisher)
25+
{
26+
services.Configure<HealthCheckPublisherOptions>(options =>
27+
{
28+
options.Delay = TimeSpan.FromSeconds(2);
29+
options.Predicate = healthCheck => healthCheck.Tags.Contains(Kentico);
30+
});
31+
32+
services.AddSingleton<IHealthCheckPublisher, KenticoEventLogHealthCheckPublisher>();
33+
}
34+
2135
return services
2236
.AddHealthChecks()
2337
.AddCheck<SiteConfigurationHealthCheck>("Site Configuration Health Check", tags: s_tags)
@@ -28,7 +42,7 @@ public static IHealthChecksBuilder AddKenticoHealthChecks(this IServiceCollectio
2842
.AddCheck<AzureSearchTaskHealthCheck>("Azure Search Task Health Checks", tags: s_tags)
2943
.AddCheck<WebFarmTaskHealthCheck>("Web Farm Task Health Check", tags: s_tags)
3044
.AddCheck<LocalSearchTaskHealthCheck>("Local Task Health Check", tags: s_tags);
31-
45+
3246
}
3347
}
3448
}

0 commit comments

Comments
 (0)