.net-core-configuration

.NET Core environment variable returns null

你。 提交于 2021-02-08 13:22:15
问题 I have a .NET Core console application. I'm trying to retrieve the environment variable using the below code. var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); However, the variable "environment" always return null. I set the environment variable "ASPNETCORE_ENVIRONMENT" through Control Panel -> System Properties -> Environment Variables -> System Variables I also tried setting the environment variable using the command set ASPNETCORE_ENVIRONMENT=development ,

.NET Core environment variable returns null

我怕爱的太早我们不能终老 提交于 2021-02-08 13:22:12
问题 I have a .NET Core console application. I'm trying to retrieve the environment variable using the below code. var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); However, the variable "environment" always return null. I set the environment variable "ASPNETCORE_ENVIRONMENT" through Control Panel -> System Properties -> Environment Variables -> System Variables I also tried setting the environment variable using the command set ASPNETCORE_ENVIRONMENT=development ,

How to inject or use IConfiguration in Azure Function V3 with Dependency Injection when configuring a service

流过昼夜 提交于 2021-01-20 15:58:33
问题 Normally in a .NET Core project I would create a 'boostrap' class to configure my service along with the DI registration commands. This is usually an extension method of IServiceCollection where I can call a method like .AddCosmosDbService and everything necessary is 'self-contained' in the static class containing that method. The key though is that the method gets an IConfiguration from the Startup class. I've worked with DI in Azure Functions in past but haven't come across this specific

How to inject or use IConfiguration in Azure Function V3 with Dependency Injection when configuring a service

巧了我就是萌 提交于 2021-01-20 15:57:32
问题 Normally in a .NET Core project I would create a 'boostrap' class to configure my service along with the DI registration commands. This is usually an extension method of IServiceCollection where I can call a method like .AddCosmosDbService and everything necessary is 'self-contained' in the static class containing that method. The key though is that the method gets an IConfiguration from the Startup class. I've worked with DI in Azure Functions in past but haven't come across this specific

How to inject or use IConfiguration in Azure Function V3 with Dependency Injection when configuring a service

你离开我真会死。 提交于 2021-01-20 15:56:42
问题 Normally in a .NET Core project I would create a 'boostrap' class to configure my service along with the DI registration commands. This is usually an extension method of IServiceCollection where I can call a method like .AddCosmosDbService and everything necessary is 'self-contained' in the static class containing that method. The key though is that the method gets an IConfiguration from the Startup class. I've worked with DI in Azure Functions in past but haven't come across this specific

How can I bind to a configuration class using ConfigurationBulder in .net core 3.1

微笑、不失礼 提交于 2020-01-05 04:12:05
问题 I want to use ConfigurationBuidler to read my appsettings.json file. I cant see what I am doing wrong. My file is { "comment": "this gets copied to bin\\debug on build. the app updates the copy. However to remember the settings you need to paste them here", "col1Width": "344" } My test fails [TestMethod] public void TestMethod1() { var configuration = Helper.LoadConfiguration("appsettings.json"); Assert.IsTrue(configuration.Properties.Keys.Contains("col1Width")); // fails here } My helper

.NET Core configuration manager, reading a dictionary where one key has a colon inside, gives an odd error message about the value, is this expected?

邮差的信 提交于 2019-12-13 02:39:43
问题 The following program: using System; using System.Collections.Generic; using Microsoft.Extensions.Configuration; namespace ConsoleApp3 { class Program { static void Main() { var builder = new ConfigurationBuilder(); builder.AddJsonFile("appsettings.json"); var configuration = builder.Build(); var options = configuration.Get<Options>(); foreach (var kvp in options.Values) Console.WriteLine($"{kvp.Key}: {kvp.Value}"); } } internal class Options { public Dictionary<string, bool> Values { get; }

How to enable Trace logging in ASP.NET Core?

元气小坏坏 提交于 2019-12-07 04:26:38
问题 I cannot get basice LogTrace(...) output in my application. Here's a repro: Create a new ASP.NET Core application using Visual Studio 2017. (Optional) comment out .UseApplicationInsights() so the repro is clearer Replace the code in ValuesController.cs with this: using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace WebApplication1.Controllers { [Route("api/[controller]")] public class ValuesController : Controller { private readonly

How to enable Trace logging in ASP.NET Core?

穿精又带淫゛_ 提交于 2019-12-05 09:26:29
I cannot get basice LogTrace(...) output in my application. Here's a repro: Create a new ASP.NET Core application using Visual Studio 2017. (Optional) comment out .UseApplicationInsights() so the repro is clearer Replace the code in ValuesController.cs with this: using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace WebApplication1.Controllers { [Route("api/[controller]")] public class ValuesController : Controller { private readonly ILogger<ValuesController> logger; public ValuesController(ILogger<ValuesController> logger) { this