0

I have a function app project where i have a mix of my code, some Azure storage interaction, some durable functions, entity framework, the whole soup. I want to be able to configure logs properly to hide irrelevant records. But the problem is that the default console logger doesn't output the Category of this or that log message so that I could add a corresponding filter in my host.json file. There is a possibility to add the "fileLoggingMode": "always" setting but that doesn't really help because it doesn't output the category either.

I assume one could simply deploy it to Azure and then grab the category from the AppInsights, but isn't there any locally available option which doesn't involve deployment?

Environment: .net7, function v4, dotnet-isolated.

UPD: just for clarity basically i wanna see a logger category for each of these log lines enter image description here

Andrey Stukalin
  • 5,328
  • 2
  • 31
  • 50
  • Could you please explain a bit more about your requirement? –  Mar 31 '23 at 14:40
  • @HariKrishna here you go! – Andrey Stukalin Mar 31 '23 at 15:35
  • I think those are host logs. Do you want to log them also in to the storage account? If yes, you can try with the `Host.Aggregator / Host.Results` to `trace` or `information` in the `host.json` under log level category. If you do not want those host logs, make it to none or you can try this setting given in this [MS Doc](https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json#override-hostjson-values) for disabling the application insights locally. –  Mar 31 '23 at 16:24
  • @HariKrishna Yep, the question is how did you know that these are host logs. Is there a way to output this information locally so that I could disable it in the `host.json`. In other words I want a generic solution, rather than asking for each logs line on SO. – Andrey Stukalin Apr 01 '23 at 07:15
  • Could try with this code in `host.json` - `"logging": { "logLevel": { "Function.YourFunctionName.User": "Information", "Function": "Error" } } ` –  Apr 01 '23 at 09:15
  • @HariKrishna of course i could try that, but that doesn't answer my original question – Andrey Stukalin Apr 01 '23 at 17:06
  • There is a program called Azure Functions Core Tools installed in the local environment to run the Azure Functions. It shows in the console on every execution, what's happening such as executing the function, started logging, host lock release, etc. which may also known as Function Runtime Logs or Host Logs depends on the logs coming. –  Apr 01 '23 at 17:11

1 Answers1

-1

AFAIK,

enter image description here

There is a program called Azure Functions Core Tools installed in the local environment to run the Azure Functions. It shows in the console on every execution, what's happening such as executing the function, started logging, host lock release (Lease acquisition), etc. which may also known as Function Runtime Logs or Host Logs depends on the logs coming.

Default Host.json code:

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}

In order to avoid this type of information logs, you can set the log level in the host.json to:

 "logLevel": {
      "Function": "Error",
    }

Also, if those collective huge logs giving more cost, set the filters in the log level categories from the host.json code as I have shown in one of workarounds.

  • As I mentioned before this kind of answer doesn't solve my *generic* problem, i.e. if I gave you another piece of my logs you'd have to propose another answer with another category and so on. My requirement is to get the category in the log output *together* with the log message so that based on this output i could configure my `host.json` file – Andrey Stukalin Apr 03 '23 at 05:44
  • Have you tried changing the `host.json` configuration to get your required/specific logs? If yes, please specify what you changed, what logs you got and what all specific logs you need both locally and also in Azure - I'll try my best to help you –  Apr 03 '23 at 06:13