Skip to content

Commit ee68af6

Browse files
committed
Add activity log diagnostic setting
1 parent 15ee69e commit ee68af6

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

articles/azure-resource-manager/bicep/scenarios-monitoring.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,27 @@ You can create Log Analytics workspaces with the resource type [Microsoft.Operat
2222

2323
## Diagnostic settings
2424

25+
Diagnostic settings enable you to configure Azure Monitor to export your logs and metrics to a number of destinations, including Log Analytics and Azure Storage.
26+
2527
When creating [diagnostic settings](../../azure-monitor/essentials/diagnostic-settings.md) in Bicep, remember that this resource is an [extension resource](scope-extension-resources.md), which means it's applied to another resource. You can create diagnostic settings in Bicep by using the resource type [Microsoft.Insights/diagnosticSettings](/azure/templates/microsoft.insights/diagnosticsettings?tabs=bicep).
2628

27-
When creating diagnostic settings in Bicep, you need to apply the scope of the diagnostic setting. The scope can be applied at the management, subscription, or resource group level. [Use the scope property on this resource to set the scope for this resource](../../azure-resource-manager/bicep/scope-extension-resources.md).
29+
When creating diagnostic settings in Bicep, you need to apply the scope of the diagnostic setting. The diagnostic setting can be applied at the management, subscription, or resource group level. [Use the scope property on this resource to set the scope for this resource](../../azure-resource-manager/bicep/scope-extension-resources.md).
2830

2931
Consider the following example:
3032

3133
::: code language="bicep" source="~/azure-docs-bicep-samples/samples/scenarios-monitoring/diagnostic-settings.bicep" :::
3234

3335
In the preceding example, you create a diagnostic setting for the App Service plan and send those diagnostics to Log Analytics. You can use the `scope` property to define your App Service plan as the scope for your diagnostic setting, and use the `workspaceId` property to define the Log Analytics workspace to send the diagnostic logs to. You can also export diagnostic settings to Event Hubs and Azure Storage Accounts.
3436

35-
Diagnostic settings differ between resources, so ensure that the diagnostic settings you want to create are applicable for the resource you're using.
37+
Log types differ between resources, so ensure that the logs you want to export are applicable for the resource you're using.
38+
39+
### Activity log diagnostic settings
40+
41+
To use Bicep to configure diagnostic settings to export the Azure activity log, deploy a diagnostic setting resource at the [subscription scope](deploy-to-subscription.md).
42+
43+
The following example shows how to export several activity log types to a Log Analytics workspace:
44+
45+
::: code language="bicep" source="temp/diagnostic-settings-activity-log.bicep" :::
3646

3747
## Alerts
3848

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
targetScope = 'subscription'
2+
3+
param logAnalyticsWorkspaceId string
4+
5+
var activityLogDiagnosticSettingsName = 'export-activity-log'
6+
7+
resource subscriptionActivityLog 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
8+
name: activityLogDiagnosticSettingsName
9+
properties: {
10+
workspaceId: logAnalyticsWorkspaceId
11+
logs: [
12+
{
13+
category: 'Administrative'
14+
enabled: true
15+
}
16+
{
17+
category: 'Security'
18+
enabled: true
19+
}
20+
{
21+
category: 'ServiceHealth'
22+
enabled: true
23+
}
24+
{
25+
category: 'Alert'
26+
enabled: true
27+
}
28+
{
29+
category: 'Recommendation'
30+
enabled: true
31+
}
32+
{
33+
category: 'Policy'
34+
enabled: true
35+
}
36+
{
37+
category: 'Autoscale'
38+
enabled: true
39+
}
40+
{
41+
category: 'ResourceHealth'
42+
enabled: true
43+
}
44+
]
45+
}
46+
}

0 commit comments

Comments
 (0)