Perform the following steps:
- Navigate to the HTTP trigger that you created and replace the following code. I just moved the line of code that logs the information to the Logs console and added the name parameter at the end of the method:
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
log.LogInformation($"C# HTTP trigger function processed a
request with the input value {name}");
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
- Now, run the function by providing the value for the name parameter with different values such as Azure Test Run 1, Azure Test Run 2 and Azure Test Run 3. This is just for demo purposes. You can use any input you like. The Logs console will show the following output:
- The logs in the preceding Logs console are only available when you are connected to the Logs console. You will not get them when you go offline. That's where Application Insights comes in handy. Navigate to the Application Insights instance that you have integrated with the Azure function app.
- Click on the Analytics button that is available in the Overview tab of Application Insights, as shown in the following screenshot:
- In the analytics query window, type the traces | sort by timestamp desc command, which returns all the traces sorted by date descending, as shown in the following screenshot: