04 - Logging & Monitoring (Dedicated)¶
Configure Application Insights and structured logging for your Dedicated (App Service Plan) PowerShell app.
Enable Application Insights¶
az monitor app-insights component create \
--app func-ps-demo-ai \
--location $LOCATION \
--resource-group $RG
az functionapp config appsettings set \
--name $APP_NAME \
--resource-group $RG \
--settings "APPLICATIONINSIGHTS_CONNECTION_STRING=<connection-string>"
az monitor app-insights component create | Create the Application Insights component for telemetry. | | --app | Name of the Application Insights component. | | --location | Azure region for the component. | | --resource-group | Resource group that contains the component. | | az functionapp config appsettings set | Point the function app at Application Insights. | | --name | Name of the function app. | | --resource-group | Resource group that contains the function app. | | --settings | Set the Application Insights connection string setting. | Logging in PowerShell¶
Use the standard streams — they flow to Application Insights automatically:
param($Request, $TriggerMetadata)
Write-Information "Processing request for $($Request.Query.Name)"
Write-Warning "Name was empty; using default"
Write-Error "Downstream call failed"
| Cmdlet | Severity |
|---|---|
Write-Information / Write-Host | Information |
Write-Warning | Warning |
Write-Error | Error |
Stream Live Logs¶
| Command/Parameter | Purpose | | --- | --- | |az functionapp log tail | Stream live log output from the function app. | | --name | Name of the function app. | | --resource-group | Resource group that contains the function app. | Verification¶
Invoke the function, then query Application Insights:
You should see your Write-Information messages.
Next Steps¶
Codify the whole environment as Infrastructure as Code.
See Also¶
- Tutorial Overview & Plan Chooser
- PowerShell Language Guide
- Platform: Hosting Plans
- Operations: Deployment
- Recipes Index