11

When my Azure Function is triggered, it logs “Executing” and “Executed” messages. This is fine during testing but as this Function gets triggered a lot, it is creating a lot of unwanted log messages. The logging that I have added myself is important to me but I would like to disable the Function's own “Executing” and “Executed” messages. To clarify, it is the following messages I don’t want logged:

Executing ‘MyFunctionName’ (Reason='New ServiceBus message detected……etc’)

Executed ‘MyFunctionName’ (Succeeded, Id=a99c6932-788f-439e-a7db-aad7f607d5ea)
Jerry Liu
  • 17,282
  • 4
  • 40
  • 61
Ian Munro
  • 197
  • 1
  • 10

2 Answers2

17

The execution logs you want to get rid of is generated by function runtime, we can set a higher log level to filter information and keep our self-defined info.

Go to Azure portal, Platform features> Function app settings> host.json

For Function app v2, with this setting in host.json, the logs excluded are nowhere to find.

{
  "version": "2.0",
  "logging": {
    "logLevel": {
      "Function.MyFunctionName.User": "Information",
      "Function": "Error"
    }
  }
}

For v1, use ILogger instead of TraceWriter. This setting in host.json only restricts those sent to Application Insights, which means we can still see them in console or file logs.

{
  "logger": {
    "categoryFilter": {
      "categoryLevels": {
        "Host.Executor": "Error"
      }
    }
  }
}
Jerry Liu
  • 17,282
  • 4
  • 40
  • 61
  • Can the "MyFunctionName" be set during deployment via an ARM template or script as the name of my function changes for each customer? – Ian Munro Nov 27 '18 at 13:20
  • @IanMunro I am afraid not. ARM template has no control over `host.json`, which is actually part of a project rather than an Azure configurable resource. – Jerry Liu Nov 28 '18 at 06:07
  • @lanMunro Do you mind accepting the solution to your original question? You could post a new question about ARM deployment to draw more attention, perhaps some experts could offer useful advice or workaround. – Jerry Liu Nov 29 '18 at 04:03
  • Whilst this does fix the problem, it has an issue if the name of the Function is changed when deployed. I have marked this as accepted as it does work but needs extra steps when changing the name on the fly. – Ian Munro Dec 05 '18 at 11:03
  • I have used this strategy on a few function recently and ran into trouble... I no longer get any customMetrics or customEvents logged into Application Insights. They come back as soon as I lower the "Function" log level to "Trace". The "Function.MyFunctionName.User" didn't help :( – vullnetyy Oct 22 '20 at 22:00
  • Thanks, "Function.MyFunctionName.User" works great! – Martin Meixger Nov 06 '20 at 10:21
  • This works well, but it not only prevents you from seeing the default info logs, it also prevents you to see your custom information logs... Do you know a way to prevent default messages like executing/executed while keeping the ones you did yourself? – Luis Gouveia Jan 09 '21 at 12:54
3

To disable built-in logging, delete the AzureWebJobsDashboard app setting.

Source: Monitor Azure Functions - Disable built-in logging

rickvdbosch
  • 14,105
  • 2
  • 40
  • 53