Reputation: 21368
How does one configure logging in Azure Functions ver 3?
The only way I managed to 'some what' configure logs is by having this in my Startup.cs (although I would like to have different configurations for local/development/production):
services.RemoveAll<IConfigureOptions<LoggerFilterOptions>>();
// don't show EF logs!!!
services.AddLogging(config => config.AddFilter("Microsoft", LogLevel.Error).AddFilter("System", LogLevel.Error));
Seems like this has no effect (local/development/other.settings.json):
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"MinerSchedule": "*/15 * * * *",
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Error",
"System": "Error",
"Microsoft.Hosting.Lifetime": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Error"
}
},
I also tried modifying host.json (as some blogs have suggested) to no avail:
host.json
{
"version": "2.0",
"logging": {
"logLevel": {
"FirstKey.DataMiner.Functions": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
}
}
how can I configure logs so that I only see Information level from my Function app?
Upvotes: 0
Views: 2201
Reputation: 15164
If you're using the isolated
model, rather than the in-process
model, then logging works differently. You could then use something like below, to set the default level above Information so you don't get all the bumf, and turn off the Host logs, but set your Function log level to Information
:
"logLevel": {
"Default": "Warning",
"Host.Aggregator": "None",
"Host.Results": "None",
"Function": "Information"
}
Additionally, you could use something like below to turn off EFCore-specific logs, too:
.ConfigureLogging(logging =>
{
logging.AddFilter("Microsoft", LogLevel.None);
logging.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.None);
})
Upvotes: 0
Reputation: 1301
We can check all the logging.info messages from Application Insights. Make sure that Applications Insights are enabled for Function App.
Steps to get the log information: Application Insights (Our function App) -> Performance -> Select “Overall” under “Operation Name” column - > Select Function Name from the under “All” logs -> Click on “View all telemetry”
Here we will be able to see the message, have a look at below screenshot for reference from my function message:
Also give a try with below json formats in hosts.json:
Sample 1:
{
"version": "2.0",
"logging": {
"logLevel": {
"ServiceLogger": "Information"
}
}
}
Sample 2:
{
"version": "2.0",
"logging": {
"logLevel": {
"ServiceLogger": "Information",
"Default": "Error",
"FirstKey.DataMiner.Functions": "Information"
}
}
}
Sample 3:
{
"version": "2.0",
"logging": {
"logLevel": {
"MyCompany.SolutionName": "Information"
}
}}
Upvotes: 1