Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem in creating own log in azure using functions

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading