skip to Main Content

I want to send custom logs to azure app insights from azure function app.
For eg i want to send error code error message and payload from azure functions to app insights

2

Answers


  1. Here’s an example:

    [FunctionName("MyFunc")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
        ILogger log)
    {
       ...
       log.LogInformation($"Hello!");
    

    For extra properties you can do the following:

    var p = new Dictionary<string, object>
    {
       ["MyExtraProperty1"] = 7
    };
    
    using var scope = log.BeginScope(p);
    log.LogWarning("Oh no!"); 
    
    Login or Signup to reply.
  2. 1.Enable AppInsights in Azure Portal

    2.Get Instrumentation Key from Azure portal for AppInsights

    3.Add key to local.settings.json:

    "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
        "APPINSIGHTS_INSTRUMENTATIONKEY": "00000000-0000-0000-0000-0000000000000"
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search