Skip to content

Commit f60782c

Browse files
committed
art2-1
1 parent 23c5fa0 commit f60782c

1 file changed

Lines changed: 57 additions & 56 deletions

File tree

articles/app-service/webjobs-sdk-get-started.md

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Get started with the Azure WebJobs SDK for Azure App Service to enable your web
2020

2121
Use Visual Studio 2022 to create a .NET 8 console app that uses the WebJobs SDK to respond to Azure Storage Queue messages, run the project locally, and finally deploy it to Azure.
2222

23-
In this tutorial, you will learn how to:
23+
In this tutorial, you'll learn how to:
2424

2525
> [!div class="checklist"]
2626
> * Create a console app
@@ -32,15 +32,15 @@ In this tutorial, you will learn how to:
3232
3333
## Prerequisites
3434

35-
* Visual Studio 2022 with the **Azure development** workload. [Install Visual Studio 2022](/visualstudio/install/).
35+
- Visual Studio 2022 with the **Azure development** workload. [Install Visual Studio 2022](/visualstudio/install/).
3636

37-
* An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
37+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
3838

3939
## Create a console app
40-
In this section, you start by creating a project in Visual Studio 2022. Next, you'll add tools for Azure development, code publishing, and functions that listen for triggers and call functions. Last, you'll set up console logging that disables a legacy monitoring tool and enables a console provider with default filtering.
40+
In this section, you start by creating a project in Visual Studio 2022. Next, you add tools for Azure development, code publishing, and functions that listen for triggers and call functions. Last, you set up console logging that disables a legacy monitoring tool and enables a console provider with default filtering.
4141

42-
>[!NOTE]
43-
>The procedures in this article are verified for creating a C# console app that runs on .NET 8.0.
42+
> [!NOTE]
43+
> The procedures in this article are verified for creating a C# console app that runs on .NET 8.0.
4444
4545
### Create a project
4646

@@ -50,27 +50,27 @@ In this section, you start by creating a project in Visual Studio 2022. Next, yo
5050

5151
1. Under **Configure your new project**, name the project *WebJobsSDKSample*, and then select **Next**.
5252

53-
1. Choose your **Target framework** and select **Create**. This tutorial has been verified using .NET 6.0.
53+
1. Choose your **Target framework** and select **Create**. This tutorial was verified using .NET 6.0.
5454

5555
### Install WebJobs NuGet packages
5656

5757
Install the latest WebJobs NuGet package. This package includes Microsoft.Azure.WebJobs (WebJobs SDK), which lets you publish your function code to WebJobs in Azure App Service.
5858

5959
1. Get the latest stable 4.x version of the [Microsoft.Azure.WebJobs.Extensions NuGet package](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions/).
6060

61-
2. In Visual Studio, go to **Tools** > **NuGet Package Manager**.
61+
1. In Visual Studio, go to **Tools** > **NuGet Package Manager**.
6262

63-
3. Select **Package Manager Console**. You'll see a list of NuGet cmdlets, a link to documentation, and a `PM>` entry point.
63+
1. Select **Package Manager Console**. You'll see a list of NuGet cmdlets, a link to documentation, and a `PM>` entry point.
6464

65-
4. In the following command, replace `<4_X_VERSION>` with the current version number you found in step 1.
65+
1. In the following command, replace `<4_X_VERSION>` with the current version number you found in step 1.
6666

6767
```powershell
6868
Install-Package Microsoft.Azure.WebJobs.Extensions -version <4_X_VERSION>
6969
```
70-
>[!NOTE]
71-
>The sample code in this article works with package versions 4.x. Make sure you use a 4.x version because you get build errors when using package versions 5.x.
70+
> [!NOTE]
71+
> The sample code in this article works with package versions 4.x. Make sure you use a 4.x version because you get build errors when using package versions 5.x.
7272
73-
5. In the **Package Manager Console**, execute the command. The extension list appears and automatically installs.
73+
1. In the **Package Manager Console**, execute the command. The extension list appears and automatically installs.
7474
7575
### Create the Host
7676
@@ -111,23 +111,23 @@ In ASP.NET Core, host configurations are set by calling methods on the [`HostBui
111111
112112
### Enable console logging
113113
114-
Set up console logging that uses the [ASP.NET Core logging framework](/aspnet/core/fundamentals/logging). This framework, Microsoft.Extensions.Logging, includes an API that works with a variety of built-in and third-party logging providers.
114+
Set up console logging that uses the [ASP.NET Core logging framework](/aspnet/core/fundamentals/logging). This framework, Microsoft.Extensions.Logging, includes an API that works with various built-in and third-party logging providers.
115115
116116
1. Get the latest stable version of the [`Microsoft.Extensions.Logging.Console` NuGet package](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Console/), which includes `Microsoft.Extensions.Logging`.
117117
118-
2. In the following command, replace `<9_X_VERSION>` with the current version number you found in step 1. Each type of NuGet Package has a unique version number.
118+
1. In the following command, replace `<9_X_VERSION>` with the current version number you found in step 1. Each type of NuGet Package has a unique version number.
119119
120120
```powershell
121121
Install-Package Microsoft.Extensions.Logging.Console -version <9_X_VERSION>
122122
```
123-
3. In the **Package Manager Console**, fill in the current version number and execute the command. The extension list appears and automatically installs.
123+
1. In the **Package Manager Console**, fill in the current version number and execute the command. The extension list appears and automatically installs.
124124

125-
4. Under the tab **Program.cs**, add this `using` statement:
125+
1. Under the tab **Program.cs**, add this `using` statement:
126126

127127
```cs
128128
using Microsoft.Extensions.Logging;
129129
```
130-
5. Continuing under **Program.cs**, add the [`ConfigureLogging`](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderextensions.configurelogging) method to [`HostBuilder`](/dotnet/api/microsoft.extensions.hosting.hostbuilder), before the `Build` command. The [`AddConsole`](/dotnet/api/microsoft.extensions.logging.consoleloggerextensions.addconsole) method adds console logging to the configuration.
130+
1. Continuing under **Program.cs**, add the [`ConfigureLogging`](/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilderextensions.configurelogging) method to [`HostBuilder`](/dotnet/api/microsoft.extensions.hosting.hostbuilder), before the `Build` command. The [`AddConsole`](/dotnet/api/microsoft.extensions.logging.consoleloggerextensions.addconsole) method adds console logging to the configuration.
131131

132132
```cs
133133
builder.ConfigureLogging((context, b) =>
@@ -166,8 +166,8 @@ Set up console logging that uses the [ASP.NET Core logging framework](/aspnet/co
166166

167167
This addition makes these changes:
168168

169-
* Disables [dashboard logging](https://github.com/Azure/azure-webjobs-sdk/wiki/Queues#logs). The dashboard is a legacy monitoring tool, and dashboard logging is not recommended for high-throughput production scenarios.
170-
* Adds the console provider with default [filtering](webjobs-sdk-how-to.md#log-filtering).
169+
- Disables [dashboard logging](https://github.com/Azure/azure-webjobs-sdk/wiki/Queues#logs). The dashboard is a legacy monitoring tool, and dashboard logging isn't recommended for high-throughput production scenarios.
170+
- Adds the console provider with default [filtering](webjobs-sdk-how-to.md#log-filtering).
171171

172172
Now, you can add a function that is triggered by messages arriving in an Azure Storage queue.
173173

@@ -181,7 +181,7 @@ In this section, you create a function triggered by messages in an Azure Storage
181181

182182
Starting with version 3 of the WebJobs SDK, to connect to Azure Storage services you must install a separate Storage binding extension package.
183183

184-
>[!NOTE]
184+
> [!NOTE]
185185
> Beginning with 5.x, Microsoft.Azure.WebJobs.Extensions.Storage has been [split by storage service](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage/CHANGELOG.md#major-changes-and-features) and has migrated the `AddAzureStorage()` extension method by service type. This version also requires you to update the version of the `Microsoft.Azure.WebJobs.Host.Storage` assembly used by the SDK.
186186
187187
1. Get the latest stable version of the [Microsoft.Azure.WebJobs.Extensions.Storage](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.Storage) NuGet package, version 5.x.
@@ -250,9 +250,9 @@ The `QueueTrigger` attribute tells the runtime to call this function when a new
250250

251251
1. In Solution Explorer, right-click the project, select **Add** > **New Item**, and then select **Class**.
252252

253-
2. Name the new C# class file *Functions.cs* and select **Add**.
253+
1. Name the new C# class file *Functions.cs* and select **Add**.
254254

255-
3. In *Functions.cs*, replace the generated template with the following code:
255+
1. In *Functions.cs*, replace the generated template with the following code:
256256

257257
```cs
258258
using Microsoft.Azure.WebJobs;
@@ -287,7 +287,8 @@ A connection string is required to configure storage. Keep this connection strin
287287
1. In **Settings**, select **Access keys**.
288288
1. For the **Connection string** under **key1**, select the **Copy to clipboard** icon.
289289

290-
![key](./media/webjobs-sdk-get-started/connection-key.png)
290+
![key](./media/webjobs-sdk-get-started/connection-key.png)
291+
:::image type="content" source="./media/webjobs-sdk-get-started/connection-key.png" alt-text="Key":::0601
291292

292293
### Configure storage to run locally
293294

@@ -315,27 +316,27 @@ Build and run the project locally and create a message queue to trigger the func
315316

316317
1. In the Azure portal, navigate to your storage account and select the **Queues** tab (1). Select **+ Queue** (2) and enter **queue** as the Queue name (3). Then, select **OK** (4).
317318

318-
![This image shows how to create a new Azure Storage Queue.](./media/webjobs-sdk-get-started/create-queue-azure-storage.png "New Azure Storage Queue")
319+
:::image type="content" source="./media/webjobs-sdk-get-started/create-queue-azure-storage.png" alt-text="This image shows how to create a new Azure Storage Queue.":::
319320

320-
2. Click the new queue and select **Add message**.
321+
1. Select the new queue and select **Add message**.
321322

322-
3. In the **Add Message** dialog, enter *Hello World!* as the **Message text**, and then select **OK**. There is now a message in the queue.
323+
1. In the **Add Message** dialog, enter *Hello World!* as the **Message text**, and then select **OK**. There is now a message in the queue.
323324

324-
![Create queue](./media/webjobs-sdk-get-started/hello-world-text.png)
325+
:::image type="content" source="./media/webjobs-sdk-get-started/hello-world-text.png" alt-text="Create queue.":::
325326

326-
4. Press **Ctrl+F5** to run the project.
327+
1. Press **Ctrl+F5** to run the project.
327328

328329
The console shows that the runtime found your function. Because you used the `QueueTrigger` attribute in the `ProcessQueueMessage` function, the WebJobs runtime listens for messages in the queue named `queue`. When it finds a new message in this queue, the runtime calls the function, passing in the message string value.
329330

330-
5. Go back to the **Queue** window and refresh it. The message is gone, since it has been processed by your function running locally.
331+
1. Go back to the **Queue** window and refresh it. The message is gone, since it has been processed by your function running locally.
331332

332-
6. Close the console window or type Ctrl+C.
333+
1. Close the console window or type Ctrl+C.
333334

334335
It's now time to publish your WebJobs SDK project to Azure.
335336

336-
## <a name="deploy-as-a-webjob"></a>Deploy to Azure
337-
338-
During deployment, you create an app service instance where you'll run your functions. When you publish a .NET console app to App Service in Azure, it automatically runs as a WebJob. To learn more about publishing, see [Develop and deploy WebJobs using Visual Studio](webjobs-dotnet-deploy-vs.md).
337+
## Deploy to Azure
338+
339+
During deployment, you create an app service instance where you run your functions. When you publish a .NET console app to App Service in Azure, it automatically runs as a WebJob. To learn more about publishing, see [Develop and deploy WebJobs using Visual Studio](webjobs-dotnet-deploy-vs.md).
339340

340341
### Create Azure resources
341342

@@ -355,10 +356,9 @@ With the web app created in Azure, it's time to publish the WebJobs project.
355356

356357
1. In the **Publish** page under **Hosting**, select the edit button and change the **WebJob Type** to `Continuous` and select **Save**. This makes sure that the WebJob is running when messages are added to the queue. Triggered WebJobs are typically used only for manual webhooks.
357358

358-
![Change WebJob type from the VS 2022 Publish window.](./media/webjobs-sdk-get-started/change-webjob-type.png)
359-
359+
:::image type="content" source="./media/webjobs-sdk-get-started/change-webjob-type.png" alt-text="Change WebJob type from the Visual Studio 2022 Publish window.":::
360360

361-
2. Select the **Publish** button at the top right corner of the **Publish** page. When the operation completes, your WebJob is running on Azure.
361+
1. Select the **Publish** button at the top right corner of the **Publish** page. When the operation completes, your WebJob is running on Azure.
362362

363363
### Create a storage connection app setting
364364

@@ -402,12 +402,13 @@ To take advantage of [Application Insights](/azure/azure-monitor/app/app-insight
402402

403403
1. Get the latest stable version of the [Microsoft.Azure.WebJobs.Logging.ApplicationInsights](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Logging.ApplicationInsights) NuGet package, version 3.x.
404404
405-
2. In the following command, replace `<3_X_VERSION>` with the current version number you found in step 1. Each type of NuGet Package has a unique version number.
405+
1. In the following command, replace `<3_X_VERSION>` with the current version number you found in step 1. Each type of NuGet Package has a unique version number.
406406

407-
```powershell
408-
Install-Package Microsoft.Azure.WebJobs.Logging.ApplicationInsights -Version <3_X_VERSION>
409-
```
410-
3. In the **Package Manager Console**, execute the command with the current version number at the `PM>` entry point.
407+
```powershell
408+
Install-Package Microsoft.Azure.WebJobs.Logging.ApplicationInsights -Version <3_X_VERSION>
409+
```
410+
411+
1. In the **Package Manager Console**, execute the command with the current version number at the `PM>` entry point.
411412

412413
### Initialize the Application Insights logging provider
413414

@@ -470,11 +471,11 @@ This initializes the Application Insights logging provider with default [filteri
470471

471472
1. Select **Search** and then select **See all data in the last 24 hours**.
472473

473-
![Select Search](./media/webjobs-sdk-get-started/select-search.png)
474+
:::image type="content" source="./media/webjobs-sdk-get-started/select-search.png" alt-text="Select Search":::
474475

475476
1. If you don't see the *Hello App Insights!* message, select **Refresh** periodically for several minutes. Logs don't appear immediately, because it takes a while for the Application Insights client to flush the logs it processes.
476477

477-
![Logs in Application Insights](./media/webjobs-sdk-get-started/logs-in-ai.png)
478+
:::image type="content" source="./media/webjobs-sdk-get-started/logs-in-ai.png" alt-text="Logs in Application Insights.":::
478479

479480
## Add input/output bindings
480481

@@ -490,7 +491,7 @@ Input bindings simplify code that reads data. For this example, the queue messag
490491
using System.IO;
491492
```
492493

493-
2. Replace the `ProcessQueueMessage` method with the following code:
494+
1. Replace the `ProcessQueueMessage` method with the following code:
494495

495496
```cs
496497
public static void ProcessQueueMessage(
@@ -504,11 +505,11 @@ Input bindings simplify code that reads data. For this example, the queue messag
504505
}
505506
```
506507

507-
In this code, `queueTrigger` is a [binding expression](../azure-functions/functions-bindings-expressions-patterns.md), which means it resolves to a different value at runtime. At runtime, it has the contents of the queue message.
508+
In this code, `queueTrigger` is a [binding expression](../azure-functions/functions-bindings-expressions-patterns.md), which means it resolves to a different value at runtime. At runtime, it has the contents of the queue message.
508509

509510
This code uses output bindings to create a copy of the file identified by the queue message. The file copy is prefixed with *copy-*.
510511

511-
3. In **Program.cs**, in the `ConfigureWebJobs` extension method, add the `AddAzureStorageBlobs` method on the [`HostBuilder`](/dotnet/api/microsoft.extensions.hosting.hostbuilder) instance (before the `Build` command) to initialize the Storage extension. At this point, the `ConfigureWebJobs` method looks like this:
512+
1. In **Program.cs**, in the `ConfigureWebJobs` extension method, add the `AddAzureStorageBlobs` method on the [`HostBuilder`](/dotnet/api/microsoft.extensions.hosting.hostbuilder) instance (before the `Build` command) to initialize the Storage extension. At this point, the `ConfigureWebJobs` method looks like this:
512513

513514
```cs
514515
builder.ConfigureWebJobs(b =>
@@ -519,21 +520,21 @@ Input bindings simplify code that reads data. For this example, the queue messag
519520
});
520521
```
521522

522-
4. Create a blob container in your storage account.
523+
1. Create a blob container in your storage account.
523524

524-
a. In the Azure portal, navigate to the **Containers** tab below **Data storage** and select **+ Container**
525+
1. In the Azure portal, navigate to the **Containers** tab below **Data storage** and select **+ Container**
525526

526-
b. In the **New container** dialog, enter *container* as the container name, and then select **Create**.
527+
1. In the **New container** dialog, enter *container* as the container name, and then select **Create**.
527528

528-
5. Upload the *Program.cs* file to the blob container. (This file is used here as an example; you could upload any text file and create a queue message with the file's name.)
529+
1. Upload the *Program.cs* file to the blob container. (This file is used here as an example; you could upload any text file and create a queue message with the file's name.)
529530

530-
a. Select the new container you created
531+
1. Select the new container you created
531532

532-
b. Select the **Upload** button.
533+
1. Select the **Upload** button.
533534

534-
![Blob upload button](./media/webjobs-sdk-get-started/blob-upload-button.png)
535+
:::image type="content" source="./media/webjobs-sdk-get-started/blob-upload-button.png" alt-text="Screenshot of the Blob upload button.":::
535536

536-
c. Find and select *Program.cs*, and then select **OK**.
537+
1. Find and select *Program.cs*, and then select **OK**.
537538

538539
### Republish the project
539540

@@ -543,7 +544,7 @@ Input bindings simplify code that reads data. For this example, the queue messag
543544

544545
1. Create a queue message in the queue you created earlier, with *Program.cs* as the text of the message.
545546

546-
![Queue message Program.cs](./media/webjobs-sdk-get-started/queue-msg-program-cs.png)
547+
:::image type="content" source="./media/webjobs-sdk-get-started/queue-msg-program-cs.png" alt-text="Queue message Program.cs":::
547548

548549
1. A copy of the file, *copy-Program.cs*, will appear in the blob container.
549550

0 commit comments

Comments
 (0)