Skip to content

Commit de34f95

Browse files
committed
add preview log section
1 parent 2a2c936 commit de34f95

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

articles/api-management/api-management-howto-log-event-hubs.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ Now that you have an Event Hub, the next step is to configure a [Logger](https:/
3030

3131
API Management loggers are configured using the [API Management REST API](https://aka.ms/apimapi). For detailed request examples, see [how to create Loggers](https://docs.microsoft.com/rest/api/apimanagement/2019-12-01/logger/createorupdate).
3232

33-
## Configure log-to-eventhubs policies
33+
## Configure log-to-eventhub policies
3434

35-
Once your logger is configured in API Management, you can configure your log-to-eventhubs policies to log the desired events. The log-to-eventhubs policy can be used in either the inbound policy section or the outbound policy section.
35+
Once your logger is configured in API Management, you can configure your log-to-eventhub policy to log the desired events. The log-to-eventhub policy can be used in either the inbound policy section or the outbound policy section.
3636

3737
1. Browse to your APIM instance.
3838
2. Select the API tab.
@@ -45,16 +45,33 @@ Once your logger is configured in API Management, you can configure your log-to-
4545
9. In the window on the right, select **Advanced policies** > **Log to EventHub**. This inserts the `log-to-eventhub` policy statement template.
4646

4747
```xml
48-
<log-to-eventhub logger-id ='logger-id'>
49-
@( string.Join(",", DateTime.UtcNow, context.Deployment.ServiceName, context.RequestId, context.Request.IpAddress, context.Operation.Name))
48+
<log-to-eventhub logger-id="logger-id">
49+
@{
50+
return new JObject(
51+
new JProperty("EventTime", DateTime.UtcNow.ToString()),
52+
new JProperty("ServiceName", context.Deployment.ServiceName),
53+
new JProperty("RequestId", context.RequestId),
54+
new JProperty("RequestIp", context.Request.IpAddress),
55+
new JProperty("OperationName", context.Operation.Name)
56+
).ToString();
57+
}
5058
</log-to-eventhub>
5159
```
52-
Replace `logger-id` with the value you used for `{new logger name}` in the URL to create the logger in the previous step.
60+
Replace `logger-id` with the value you used for `{loggerId}` in the request URL to create the logger in the previous step.
5361

54-
You can use any expression that returns a string as the value for the `log-to-eventhub` element. In this example, a string containing the date and time, service name, request id, request ip address, and operation name is logged.
62+
You can use any expression that returns a string as the value for the `log-to-eventhub` element. In this example, a string in JSON format containing the date and time, service name, request id, request ip address, and operation name is logged.
5563

5664
Click **Save** to save the updated policy configuration. As soon as it is saved the policy is active and events are logged to the designated Event Hub.
5765

66+
## Preview the log in Event Hub using Azure Stream Analytics
67+
68+
You can preview the log in Event Hub using [Azure Stream Analytics queries](https://docs.microsoft.com/azure/event-hubs/process-data-azure-stream-analytics).
69+
70+
1. In Azure Portal, browse to the Event Hub that the logger sends events to.
71+
2. Select **Process data** tab under **Features**.
72+
3. Click **Explore** button on **Enable real time insights from events** card.
73+
4. You should be able to preview the log on **Input preview** tab. If the data shown isn't current, select **Refresh** to see the latest events.
74+
5875
## Next steps
5976
* Learn more about Azure Event Hubs
6077
* [Get started with Azure Event Hubs](../event-hubs/event-hubs-c-getstarted-send.md)

0 commit comments

Comments
 (0)