Skip to content

Commit 82790ab

Browse files
authored
Add details about "." in env var name (#22915)
* Added cross-platform bits for env vars, and note/link re: . in names * Pre-commit hook, applied automatic markdownlint CLI fixes * Apply suggestions from code review
1 parent d179551 commit 82790ab

File tree

3 files changed

+84
-38
lines changed

3 files changed

+84
-38
lines changed

docs/architecture/dapr-for-net-developers/bindings.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ The Dapr .NET SDK provides language-specific support for .NET Core developers. I
119119
private async Task SendSMSAsync([FromServices] DaprClient daprClient)
120120
{
121121
var message = "Welcome to this awesome service";
122-
var metadata = new Dictionary<string, string>
123-
{
124-
{ "toNumber", "555-3277" }
122+
var metadata = new Dictionary<string, string>
123+
{
124+
{ "toNumber", "555-3277" }
125125
};
126126
await daprClient.InvokeBindingAsync("sms", "create", message, metadata);
127127
}
@@ -220,7 +220,7 @@ public Task Handle(OrderStartedDomainEvent notification, CancellationToken cance
220220
{
221221
var string message = CreateEmailBody(notification);
222222
var metadata = new Dictionary<string, string>
223-
{
223+
{
224224
{"emailFrom", "[email protected]"},
225225
{"emailTo", notification.UserName},
226226
{"subject", $"Your eShopOnDapr order #{notification.Order.Id}"}

docs/architecture/dapr-for-net-developers/getting-started.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ You can invoke Dapr APIs across any development platform using Dapr's native sup
7474
using System.Threading.Tasks;
7575
using Dapr;
7676
using Dapr.Client;
77-
77+
7878
namespace DaprCounter
7979
{
8080
class Program
8181
{
8282
static async Task Main(string[] args)
8383
{
8484
var daprClient = new DaprClientBuilder().Build();
85-
85+
8686
var counter = await daprClient.GetStateAsync<int>("statestore", "counter");
87-
87+
8888
while (true)
8989
{
9090
Console.WriteLine($"Counter = {counter++}");
91-
91+
9292
await daprClient.SaveStateAsync("statestore", "counter", counter);
93-
93+
9494
await Task.Delay(1000);
9595
}
9696
}
@@ -256,17 +256,17 @@ Now, you'll configure communication between the services using Dapr [service inv
256256

257257
```csharp
258258
using System;
259-
259+
260260
namespace DaprFrontEnd
261261
{
262262
public class WeatherForecast
263263
{
264264
public DateTime Date { get; set; }
265-
265+
266266
public int TemperatureC { get; set; }
267-
267+
268268
public int TemperatureF { get; set; }
269-
269+
270270
public string Summary { get; set; }
271271
}
272272
}
@@ -316,7 +316,7 @@ Now, you'll configure communication between the services using Dapr [service inv
316316
@{
317317
ViewData["Title"] = "Home page";
318318
}
319-
319+
320320
<div class="text-center">
321321
<h1 class="display-4">Welcome</h1>
322322
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
@@ -349,14 +349,14 @@ In the final part of this example, you'll add container support and run the solu
349349

350350
```yaml
351351
version: '3.4'
352-
352+
353353
services:
354354
daprfrontend:
355355
image: ${DOCKER_REGISTRY-}daprfrontend
356356
build:
357357
context: .
358358
dockerfile: DaprFrontEnd/Dockerfile
359-
359+
360360
```
361361

362362
The *.dockerignore* file contains file types and extensions that you don't want Docker to include in the container. These files are associated with the development environment and source control and not the app or service you're deploying.
@@ -367,14 +367,14 @@ In the final part of this example, you'll add container support and run the solu
367367

368368
```yaml
369369
version: '3.4'
370-
370+
371371
services:
372372
daprfrontend:
373373
image: ${DOCKER_REGISTRY-}daprfrontend
374374
build:
375375
context: .
376376
dockerfile: DaprFrontEnd/Dockerfile
377-
377+
378378
daprbackend:
379379
image: ${DOCKER_REGISTRY-}daprbackend
380380
build:
@@ -386,37 +386,37 @@ In the final part of this example, you'll add container support and run the solu
386386

387387
```yaml
388388
version: '3.4'
389-
389+
390390
services:
391391
daprfrontend:
392392
image: ${DOCKER_REGISTRY-}daprfrontend
393393
build:
394394
context: .
395395
dockerfile: DaprFrontEnd/Dockerfile
396396
ports:
397-
- "51000:50001"
398-
397+
- "51000:50001"
398+
399399
daprfrontend-dapr:
400400
image: "daprio/daprd:latest"
401401
command: [ "./daprd", "-app-id", "daprfrontend", "-app-port", "80" ]
402402
depends_on:
403403
- daprfrontend
404404
network_mode: "service:daprfrontend"
405-
405+
406406
daprbackend:
407407
image: ${DOCKER_REGISTRY-}daprbackend
408408
build:
409409
context: .
410410
dockerfile: DaprBackEnd/Dockerfile
411411
ports:
412412
- "52000:50001"
413-
413+
414414
daprbackend-dapr:
415415
image: "daprio/daprd:latest"
416416
command: [ "./daprd", "-app-id", "daprbackend", "-app-port", "80" ]
417417
depends_on:
418418
- daprfrontend
419-
network_mode: "service:daprbackend"
419+
network_mode: "service:daprbackend"
420420
```
421421

422422
In the updated file, we've added `daprfrontend-dapr` and `daprbackend-dapr` sidecars for the `daprfrontend` and `daprbackend` services respectively. In the updated file, pay close attention to the following changes:

docs/core/extensions/logging.md

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Logging in .NET
33
author: IEvangelist
44
description: Learn how to use the logging framework provided by the Microsoft.Extensions.Logging NuGet package.
55
ms.author: dapine
6-
ms.date: 09/30/2020
6+
ms.date: 02/19/2021
77
---
88

99
# Logging in .NET
@@ -87,29 +87,75 @@ In the preceding sample:
8787

8888
### Set log level by command line, environment variables, and other configuration
8989

90-
Log level can be set by any of the [configuration providers](configuration-providers.md).
90+
Log level can be set by any of the [configuration providers](configuration-providers.md). For example, you can create a persisted environment variable named `Logging:LogLevel:Microsoft` with a value of `Information`.
9191

92-
The following commands:
92+
## [Command Line](#tab/command-line)
9393

94-
- Set the environment key `Logging:LogLevel:Microsoft` to a value of `Information` on Windows.
95-
- Test the settings when using an app created with the .NET Worker service templates. The `dotnet run` command must be run in the project directory after using `set`.
94+
Create and assign persisted environment variable, given the log level value.
9695

97-
```cmd
98-
set Logging__LogLevel__Microsoft=Information
99-
dotnet run
96+
```CMD
97+
:: Assigns the env var to the value
98+
setx "Logging__LogLevel__Microsoft" "Information" /M
99+
```
100+
101+
In a *new* instance of the **Command Prompt**, read the environment variable.
102+
103+
```CMD
104+
:: Prints the env var value
105+
echo %Logging__LogLevel__Microsoft%
106+
```
107+
108+
## [PowerShell](#tab/powershell)
109+
110+
Create and assign persisted environment variable, given the log level value.
111+
112+
```powershell
113+
# Assigns the env var to the value
114+
[System.Environment]::SetEnvironmentVariable(
115+
"Logging__LogLevel__Microsoft", "Information", "Machine")
116+
```
117+
118+
In a *new* instance of the **PowerShell**, read the environment variable.
119+
120+
```powershell
121+
# Prints the env var value
122+
[System.Environment]::GetEnvironmentVariable(
123+
"Logging__LogLevel__Microsoft", "Machine")
100124
```
101125

102-
The preceding environment setting:
126+
## [Bash](#tab/bash)
103127

104-
- Is only set in processes launched from the command window they were set in.
105-
- Isn't read by apps launched with Visual Studio.
128+
Create and assign persisted environment variable, given the log level value.
106129

107-
The following [setx](/windows-server/administration/windows-commands/setx) command also sets the environment key and value on Windows. Unlike `set`, `setx` settings are persisted. The `/M` switch sets the variable in the system environment. If `/M` isn't used, a user environment variable is set.
130+
```Bash
131+
# Assigns the env var to the value, persists it across sessions
132+
echo export Logging__LogLevel__Microsoft="Information" >> ~/.bashrc && source ~/.bashrc
133+
```
134+
135+
To read the environment variable.
136+
137+
```Bash
138+
# Prints the env var value
139+
echo $Logging__LogLevel__Microsoft
108140

109-
```cmd
110-
setx Logging__LogLevel__Microsoft=Information /M
141+
# Or use printenv:
142+
# printenv Logging__LogLevel__Microsoft
111143
```
112144

145+
> [!NOTE]
146+
> When configuring environment variables with names that contain `.` (periods), consider the "Exporting a variable with a dot (.) in it" question on **Stack Exchange** and its corresponding [accepted answer](https://unix.stackexchange.com/a/93533).
147+
148+
---
149+
150+
The preceding environment setting is persisted in the environment. To test the settings when using an app created with the .NET Worker service templates, use the `dotnet run` command in the project directory after the environment variable is assigned.
151+
152+
```dotnetcli
153+
dotnet run
154+
```
155+
156+
> [!TIP]
157+
> After setting an environment variable, restart your integrated development environment (IDE) to ensure that newly added environment variables are available.
158+
113159
On [Azure App Service](https://azure.microsoft.com/services/app-service/), select **New application setting** on the **Settings > Configuration** page. Azure App Service application settings are:
114160

115161
- Encrypted at rest and transmitted over an encrypted channel.

0 commit comments

Comments
 (0)