Mr_road
Mr_road

Reputation: 564

Azure - Logging Request Details to EventHub from API Management

The basic example provided by Microsoft when I add the Log to EventHub action to my Incoming processing is useful but I want to be able to log the Request Content and Content Length. Currently I cannot find any documentation or definitions of the context or context.Request objects used in this example.

<log-to-eventhub logger-id ='logger-id'>
  @( string.Join(",", DateTime.UtcNow, context.Deployment.ServiceName, context.RequestId, context.Request.IpAddress, context.Operation.Name))
</log-to-eventhub>

Can someone please point me to the documentation for this, or at least tell me how to get the content of the request body or the body length?

Upvotes: 4

Views: 866

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35124

Here is how you can get the body:

string inBody = context.Request.Body.As<string>(preserveContent: true); 

For more information, see the context, context.Request and IMessage sections in the Context variable table.

Upvotes: 5

Related Questions