You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/host-and-deploy/health-checks.md
+15-27Lines changed: 15 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Learn how to set up health checks for ASP.NET Core infrastructure,
5
5
monikerRange: '>= aspnetcore-2.2'
6
6
ms.author: riande
7
7
ms.custom: mvc
8
-
ms.date: 11/13/2019
8
+
ms.date: 12/15/2019
9
9
uid: host-and-deploy/health-checks
10
10
---
11
11
# Health checks in ASP.NET Core
@@ -294,9 +294,7 @@ app.UseEndpoints(endpoints =>
294
294
295
295
### Customize output
296
296
297
-
The <xref:Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions.ResponseWriter> option gets or sets a delegate used to write the response.
298
-
299
-
In `Startup.Configure`:
297
+
In `Startup.Configure`, set the [HealthCheckOptions.ResponseWriter](xref:Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions.ResponseWriter) option to a delegate for writing the response:
The default delegate writes a minimal plaintext response with the string value of [HealthReport.Status](xref:Microsoft.Extensions.Diagnostics.HealthChecks.HealthReport.Status). The following custom delegate, `WriteResponse`, outputs a custom JSON response:
309
+
The default delegate writes a minimal plaintext response with the string value of [HealthReport.Status](xref:Microsoft.Extensions.Diagnostics.HealthChecks.HealthReport.Status). The following custom delegates output a custom JSON response.
The health checks system doesn't provide built-in support for complex JSON return formats because the format is specific to your choice of monitoring system. Feel free to customize the `JObject` in the preceding example as necessary to meet your needs.
315
+
The second example demonstrates how to use [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/):
In the sample app, comment out the `SYSTEM_TEXT_JSON`[preprocessor directive](xref:index#preprocessor-directives-in-sample-code) in *CustomWriterStartup.cs* to enable the `Newtonsoft.Json` version of `WriteResponse`.
320
+
321
+
The health checks API doesn't provide built-in support for complex JSON return formats because the format is specific to your choice of monitoring system. Customize the response in the preceding examples as needed. For more information on JSON serialization with `System.Text.Json`, see [How to serialize and deserialize JSON in .NET](/dotnet/standard/serialization/system-text-json-how-to).
332
322
333
323
## Database probe
334
324
@@ -525,11 +515,11 @@ The sample app demonstrates a memory health check with a custom response writer.
525
515
526
516
Registerhealthcheckserviceswith<xref:Microsoft.Extensions.DependencyInjection.HealthCheckServiceCollectionExtensions.AddHealthChecks*>in `Startup.ConfigureServices`. Insteadofenablingthehealthcheckbypassingitto<xref:Microsoft.Extensions.DependencyInjection.HealthChecksBuilderAddCheckExtensions.AddCheck*>, the `MemoryHealthCheck` isregisteredasaservice. All <xref:Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck>registeredservicesareavailabletothehealthcheckservicesandmiddleware. WerecommendregisteringhealthcheckservicesasSingletonservices.
Ahealthcheckendpointiscreatedbycalling `MapHealthChecks` in `Startup.Configure`. A `WriteResponse` delegateisprovidedtothe`ResponseWriter`propertytooutputacustomJSONresponse when the health check executes:
522
+
Ahealthcheckendpointiscreatedbycalling `MapHealthChecks` in `Startup.Configure`. A `WriteResponse` delegateisprovidedtothe<Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions.ResponseWriter>propertytooutputacustomJSONresponse when the health check executes:
533
523
534
524
```csharp
535
525
app.UseEndpoints(endpoints =>
@@ -541,9 +531,7 @@ app.UseEndpoints(endpoints =>
541
531
}
542
532
```
543
533
544
-
The `WriteResponse` methodformatsthe `CompositeHealthCheckResult` intoaJSONobjectandyieldsJSONoutputforthehealthcheckresponse:
0 commit comments