Can anyone give information ( to be precise an example code) on how to create own logs that should be given to azure application insights using soome azure trigger function.
Thanks in Advance, any help will be appreciated
CodePudding user response:
You can use Logger and Iloggger, we can use Log.Warning or Log.information for creating your own log :
Function.cs:
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace FunctionApp1
{
public class MainFunction
{
[FunctionName("MainFunction")]
public void Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
_logger.LogInformation($" Hey SAKR THIS IS FOR YOU");
_logger.LogInformation($" SAKR COMPLETED YOUR WORK");
}}
}
host.json :
{
"version": "2.0",
"logging": {
"logLevel": {
"Function": "Trace"
}
}
}
Output: