0

I currently have the below implementation for my HealthCheck:

This is my appsettings.json:

  "HealthCheckUrls": {
    "TestUrl": "http://test.com",
    "TestUrl2": "http://test2.com" 
    } 

In my ConfigureService method, I have the below:

 services.AddHealthChecks()
          .AddUrlGroup("get url from config here","urlname"); // Need to get url from config here

Is it possible to read the urls from the config file? I tried the below but does not work.

 services.AddHealthChecks()
          .AddUrlGroup(Configuration.GetSection("HealthCheckUrls:TestUrl"),"urlname");
avdeveloper
  • 449
  • 6
  • 30
  • https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-5.0#register-health-check-services in fact there are a bunch of ways to achieve this – TheGeneral Sep 15 '21 at 08:33
  • Does this answer your question? [How to read AppSettings values from a .json file in ASP.NET Core](https://stackoverflow.com/questions/31453495/how-to-read-appsettings-values-from-a-json-file-in-asp-net-core) – Ergis Sep 15 '21 at 10:28

1 Answers1

0
You can get values from Appsettings.json file from below code snippt,

        Create variable of IConfiguration _iconfiguration in the controller class like
          public HomeController(IConfiguration iconfiguration) {  
                    _iconfiguration = iconfiguration;  
                }  
     string strTestUrl = _iconfiguration.GetSection("HealthCheckUrls").GetSection("TestUrl").Value;  
     string strTestUrl2= _iconfiguration.GetSection("HealthCheckUrls").GetSection("TestUrl2").Value;