Getting Value from appsettings.json in .NET Core

PHOTO EMBED

Wed Apr 20 2022 18:53:16 GMT+0000 (Coordinated Universal Time)

Saved by @iamsingularity #csharp

namespace FetchAppsettingsValue.Controllers
{
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Options;
    using System.Collections.Generic;

    [Route("api/Option")]
    [ApiController]
    public class OptionController : ControllerBase
    {
        private readonly IOptions<Logging> _logging;
        public OptionController(IOptions<Logging> logging)
        {
            _logging = logging;
        }

        // GET: api/Option
        [HttpGet]
        public IEnumerable<string> Get()
        {
            var result = _logging.Value.LogLevel.Default; // "Information"

            return new string[] { result };
        }
    }
}
content_copyCOPY

https://www.telerik.com/blogs/how-to-get-values-from-appsettings-json-in-net-core