Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Log Level for Azure Functions

I have an Azure Function App which has Application Insights configured. My functions have some LogTrace() messages in but they are not being captured by AppInsights. Do I have to configure a minimum loglevel somewhere?

like image 774
phil Avatar asked Mar 28 '19 22:03

phil


People also ask

How can we configure log level for Azure Functions?

In your function app, select Configuration under Settings, and then select Application settings. If you see a setting named APPINSIGHTS_INSTRUMENTATIONKEY , Application Insights integration is enabled for your function app running in Azure.

Where do Azure function logs go?

In the path of Storage Account > File Shares (under Data Storage) > Your Function App > LogFiles > Application > Functions > Function > Your Function Name > You can see the console result (Application Logs - Execution results/failed result/error data) of the function.

How do I check logs on Azure function app?

To query the generated logs: From your function app, select Diagnostic settings. From the Diagnostic settings list, select the Log Analytics workspace that you configured to send the function logs to. From the Log Analytics workspace page, select Logs.

How do I monitor my Azure function?

Azure Functions can be monitored using Application Insights and Azure Monitor. Though Azure provides such monitoring solutions, users cannot monitor multiple entities with various metrics. Whereas, with Serverless360 monitoring, it is possible to monitor various entities based on metrics at the Application level.


1 Answers

Please take a look at this article on how to set log level for function v1 or v2.

In the file host.json, for the filed "Function", set its value to Trace. Then LogTrace() can be logged into application insights.

Sample host.json for Azure function v2, which can log trace messages to Application Insights:

{   "version": "2.0",   "logging": {     "fileLoggingMode": "always",     "logLevel": {       "default": "Information",       "Host.Results": "Error",       "Function": "Trace",       "Host.Aggregator": "Trace"     }   } } 

And if you publish your function app with visual studio, you can modify your host.json file as per the above before publishing.

And if you want to change the log level in azure portal, please follow this:

In Azure portal, navigate to your function app -> in the function app settings, make sure enable the Read/Write, then change log level to trace in the host.json.

enter image description here

like image 88
Ivan Yang Avatar answered Sep 21 '22 13:09

Ivan Yang