Reputation: 5500
Currently I am working on Azure API management, in that I imported one API after that configured the event hub policy to send API logs into event hub. Up to now everything working fine.
I configured event hub policy by using this below lines of code.
<log-to-eventhub logger-id="azure12113apimdemo-logger">
@(string.Join(",", DateTime.UtcNow, context.Deployment.ServiceName, context.RequestId, context.Request.IpAddress, context.Operation.Name) )
</log-to-eventhub>
The data available in the event hub with the below format, but I want to send the same data with JSON format to event hub. Because of by using the JSON data only we can send those data power bi through stream analytics Job.
Sample data available in the event hub:
5/5/2017 12:34:36 PM, azureapi12123mdemo.azure-api.net, a81f5391-7532-49b1-8b43-9d8916157qwqw945, 50.71.221.200, CustomerTables_GetCustomerTables
Can you please tell me how send API logs in the JSON format to event hub by configuring the event hub policy in API management?
Upvotes: 1
Views: 903
Reputation: 35124
In worst case you could do string.Format
instead of string.Join
to produce JSON manually.
But you should be able to use JObject
too:
@{
var json = new JObject(
new JProperty("DateTime", DateTime.UtcNow),
new JProperty("ServiceName", context.Deployment.ServiceName),
new JProperty("RequestId", context.RequestId),
new JProperty("IP", context.Request.IpAddress),
new JProperty("Operation", context.Operation.Name)
);
return json.ToString();
}
Upvotes: 2