// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
namespace Microsoft.Extensions.Diagnostics.HealthChecks
{
///
/// Represents the result of a health check.
///
public struct HealthCheckResult
{
private static readonly IReadOnlyDictionary _emptyReadOnlyDictionary = new Dictionary();
///
/// Creates a new with the specified values for , ,
/// , and .
///
/// A value indicating the pass/fail status of the component that was checked.
/// A human-readable description of the status of the component that was checked.
/// An representing the exception that was thrown when checking for status (if any).
/// Additional key-value pairs describing the health of the component.
public HealthCheckResult(bool result, string description, Exception exception, IReadOnlyDictionary data)
{
Result = result;
Description = description;
Exception = exception;
Data = data ?? _emptyReadOnlyDictionary;
}
///
/// Gets additional key-value pairs describing the health of the component.
///
public IReadOnlyDictionary Data { get; }
///
/// Gets a human-readable description of the status of the component that was checked.
///
public string Description { get; }
///
/// Gets an representing the exception that was thrown when checking for status (if any).
///
public Exception Exception { get; }
///
/// Gets a value indicating the pass/fail status of the component that was checked. If true, then the component
/// is considered to have passed health validation. A false value will be mapped to the configured
/// by the health check system.
///
public bool Result { get; }
///
/// Creates a representing a passing component.
///
/// A representing a passing component.
/// A human-readable description of the status of the component that was checked. Optional.
/// Additional key-value pairs describing the health of the component. Optional.
public static HealthCheckResult Passed(string description = null, IReadOnlyDictionary data = null)
{
return new HealthCheckResult(result: true, description, exception: null, data);
}
///
/// Creates a representing an failing component.
///
/// A human-readable description of the status of the component that was checked. Optional.
/// An representing the exception that was thrown when checking for status. Optional.
/// Additional key-value pairs describing the health of the component. Optional.
/// A representing an failing component.
public static HealthCheckResult Failed(string description = null, Exception exception = null, IReadOnlyDictionary data = null)
{
return new HealthCheckResult(result: false, description, exception, data);
}
}
}