0

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?

ShaneKm
  • 20,823
  • 43
  • 167
  • 296
  • Have you seen this issue: [Remove filters for ILoggers created by customer DI](https://github.com/Azure/azure-functions-host/issues/4345) – Mo Nazemi Aug 19 '21 at 00:01
  • Don't define in any thing in .cs file for remove any filter. Use `host.json` to define the log level. `"logging": { "logLevel": { "Default": "Error", "FirstKey.DataMiner.Functions": "Information" }`. Set the "Default to higher log level and the your namespace with `information` log level. – user1672994 Aug 19 '21 at 04:39

1 Answers1

0

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:

LogInfo

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"
    }
  }}
SaiKarri-MT
  • 1,174
  • 1
  • 3
  • 8