为服务总线启用诊断日志Enable diagnostics logs for Service Bus

开始使用 Azure 服务总线命名空间时,你可能想要监视命名空间的创建、删除或访问方式和时间。When you start using your Azure Service Bus namespace, you might want to monitor how and when your namespace is created, deleted, or accessed. 本文概述所有可用的操作日志和诊断日志。This article provides an overview of all the operational and diagnostics logs that are available.

Azure 服务总线目前支持活动日志和操作日志,这些日志捕获针对 Azure 服务总线命名空间执行的管理操作。Azure Service Bus currently supports activity and operational logs, which capture management operations that are performed on the Azure Service Bus namespace. 具体而言,这些日志捕获操作类型,包括队列创建、所用的资源和操作状态。Specifically, these logs capture the operation type, including queue creation, resources used, and the status of the operation.

操作日志架构Operational logs schema

所有日志均以 JavaScript 对象表示法 (JSON) 格式存储在以下两个位置:All logs are stored in JavaScript Object Notation (JSON) format in the following two locations:

  • AzureActivity:显示通过 Azure 门户或 Azure 资源管理器模板部署对命名空间执行操作时生成的日志。AzureActivity: Displays logs from operations and actions that are conducted against your namespace in the Azure portal or through Azure Resource Manager template deployments.
  • AzureDiagnostics:显示使用 API 或通过语言 SDK 中的管理客户端对命名空间执行操作时生成的日志。AzureDiagnostics: Displays logs from operations and actions that are conducted against your namespace by using the API, or through management clients on the language SDK.

操作日志 JSON 字符串包含下表列出的元素:Operational log JSON strings include the elements listed in the following table:

名称Name 说明Description
ActivityIdActivityId 内部 ID,用于标识指定的活动Internal ID, used to identify the specified activity
EventNameEventName 操作名称Operation name
ResourceIdResourceId Azure Resource Manager 资源 IDAzure Resource Manager resource ID
SubscriptionIdSubscriptionId 订阅 IDSubscription ID
EventTimeStringEventTimeString 操作时间Operation time
EventPropertiesEventProperties 操作属性Operation properties
状态Status 操作状态Operation status
调用方Caller 操作的调用方(Azure 门户或管理客户端)Caller of operation (the Azure portal or management client)
CategoryCategory OperationalLogsOperationalLogs

下面是运行日志 JSON 字符串的示例:Here's an example of an operational log JSON string:

{
  "ActivityId": "6aa994ac-b56e-4292-8448-0767a5657cc7",
  "EventName": "Create Queue",
  "resourceId": "/SUBSCRIPTIONS/1A2109E3-9DA0-455B-B937-E35E36C1163C/RESOURCEGROUPS/DEFAULT-SERVICEBUS-CENTRALUS/PROVIDERS/MICROSOFT.SERVICEBUS/NAMESPACES/SHOEBOXEHNS-CY4001",
  "SubscriptionId": "1a2109e3-9da0-455b-b937-e35e36c1163c",
  "EventTimeString": "9/28/2016 8:40:06 PM +00:00",
  "EventProperties": "{\"SubscriptionId\":\"1a2109e3-9da0-455b-b937-e35e36c1163c\",\"Namespace\":\"shoeboxehns-cy4001\",\"Via\":\"https://shoeboxehns-cy4001.servicebus.chinacloudapi.cn/f8096791adb448579ee83d30e006a13e/?api-version=2016-07\",\"TrackingId\":\"5ee74c9e-72b5-4e98-97c4-08a62e56e221_G1\"}",
  "Status": "Succeeded",
  "Caller": "ServiceBus Client",
  "category": "OperationalLogs"
}

在操作日志中捕获的事件和操作Events and operations captured in operational logs

操作日志捕获针对 Azure 服务总线命名空间执行的所有管理操作。Operational logs capture all management operations that are performed on the Azure Service Bus namespace. 针对 Azure 服务总线执行的数据操作量很大,因此不会捕获数据操作。Data operations are not captured, because of the high volume of data operations that are conducted on Azure Service Bus.

备注

为了帮助你更好地跟踪数据操作,我们建议使用客户端跟踪。To help you better track data operations, we recommend using client-side tracing.

在操作日志中捕获以下管理操作:The following management operations are captured in operational logs:

作用域Scope 操作Operation
命名空间Namespace
  • 创建命名空间Create Namespace
  • 更新命名空间Update Namespace
  • 删除命名空间Delete Namespace
  • 更新命名空间 SharedAccess 策略Update Namespace SharedAccess Policy
队列Queue
  • 创建队列Create Queue
  • 更新队列Update Queue
  • 删除队列Delete Queue
  • 自动删除 - 删除队列AutoDelete Delete Queue
主题Topic
  • 创建主题Create Topic
  • 更新主题Update Topic
  • 删除主题Delete Topic
  • 自动删除 - 删除主题AutoDelete Delete Topic
订阅Subscription
  • 创建订阅Create Subscription
  • 更新订阅Update Subscription
  • 删除订阅Delete Subscription
  • 自动删除 - 删除订阅AutoDelete Delete Subscription

备注

目前,不会在操作日志中跟踪“读取”操作。Currently, Read operations are not tracked in the operational logs.

启用操作日志Enable operational logs

操作日志默认已禁用。Operational logs are disabled by default. 若要启用诊断日志,请执行以下操作:To enable diagnostics logs, do the following:

  1. Azure 门户中,转到你的 Azure 服务总线命名空间,然后在“监视”下选择“诊断设置”。In the Azure portal, go to your Azure Service Bus namespace and then, under Monitoring, select Diagnostic settings.

    “诊断设置”链接

  2. 在“诊断设置”窗格中,选择“添加诊断设置”。In the Diagnostics settings pane, select Add diagnostic setting.

    “添加诊断设置”链接

  3. 执行以下操作来配置诊断设置:Configure the diagnostics settings by doing the following:

    a.a. 在“名称”框中,输入诊断设置的名称。In the Name box, enter a name for the diagnostics settings.

    b.b. 为诊断日志选择以下三个目标之一:Select one of the following three destinations for your diagnostics logs:

    • 如果选择“存档到存储帐户”,则需要配置用于存储诊断日志的存储帐户。If you select Archive to a storage account, you need to configure the storage account where the diagnostics logs will be stored.
    • 如果选择“流式传输到事件中心”,则需要配置要将诊断日志流式传输到的事件中心。If you select Stream to an event hub, you need to configure the event hub that you want to stream the diagnostics logs to.
    • 如果选择“发送到 Log Analytics”,则需要指定要将诊断发送到的 Log Analytics 实例。If you select Send to Log Analytics, you need to specify which instance of Log Analytics the diagnostics will be sent to.

    c.c. 选中“OperationalLogs”复选框。Select the OperationalLogs check box.

    “诊断设置”窗格

  4. 选择“保存” 。Select Save.

新设置将在大约 10 分钟后生效。The new settings take effect in about 10 minutes. 日志将显示在“诊断日志”窗格中配置的存档目标中。The logs are displayed in the configured archival target, in the Diagnostics logs pane.

有关配置诊断设置的详细信息,请参阅 Azure 诊断日志概述For more information about configuring diagnostics settings, see the overview of Azure diagnostics logs.

后续步骤Next steps

若要详细了解服务总线,请参阅:To learn more about Service Bus, see: