I'm curious if there's a way for overriding the loglevel of the azure function default or built-in logs.
I've attached a screenshot below with some examples of the unwanted logs.
I've found out that I can override the setting for my custom logs in app.settings by adding this:
AzureFunctionsJobHost__logging__LogLevel__Default
Is there a way to differentiate my custom logs from the default logging?
Stop an Azure Function from logging the “Executing” and “Executed” messages
I went through this post, but I noticed people complaining about their custom information logs not being logged into app insights anymore.
Also, I've read some Microsoft documentation about a settings AzureWebJobsDashboard that you should delete if you want to disable built-in logging. However, I can't find this setting in the azure function app.settings.
I would highly appreciate if someone would clarify this topic for me, I'm kind of a junior with Azure. Also sorry if this post is spam.
Thank you for your time! :D
Overriding the loglevel of the azure function default or built-in logs
Yes, we can override function log level after deployed into azure.
After deployed in azure if you want to override logging keep adding the AzureFunctionsJobHost__path__to__setting setting in Application Settings in function Configuration. If you added the settings in Application
Settings it will override into host.json
AzureFunctionsJobHost__path__to__setting
I have added in my function and the local.settings.json. In Below default log level has information "default": "Information" changing to Debug using "AzureFunctionsJobHost__logging__logLevel__Default": "Debug".
After deployment Use portal to override.
Disable the Specific function logging:
In host.json while logging your function telemetry information we are using log levels and categories Ms-Doc. Use Log Level has None to disable the specified category log.
"logLevel": {
"default": "Information",
"Host.Results": "Error", // Host.Results will collect only Error
"Function": "None", // Disable logging for the Function catagory
"Host.Aggregator": "Trace"
}
Related
One can use app settings AzureWebJobs.<FUNCTION_NAME>.Disabled to disable individual Functions in an Azure Function. However, that of course requires that you know all the Function names.
Is there a way to disable all Functions in a similar way? (and no, just Stopping the function app is not an option).
In Local Azure Function Project, we can add the disabled attribute for the multiple functions we need to disable:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobs.BlobTriggerFunction.Disabled": true,
"AzureWebJobs.SingleTonTimerFunction.Disabled": true
}
}
As you're adding the custom attribute using C# class library in every function code like [Disable("FUNCTION_DISABLED")] which is also considerable but using application settings is recommended as specified in this MS Doc.
I have 3 different functions in which 2 are disabled using the above code.
One of the similar issues is in open state in GitHub regarding disabling all the functions at a time is a feature request and there are some temporary workarounds given which is possible using App Settings in the Portal Azure Function Configuration Menu but that is regarding to specific slot.
I have so far used the appsettings.{environment}.json files to keep application level configuration settings. Now I encounter this tab in Azure Portal for an App Service.
What is the difference between using the appsettings.json files and "Application Settings" Tab in the Azure Portal? And which one to use When?
difference between using the appsettings.json files and "Application Settings" Tab in the Azure Portal? And which one to use When?
If you are using more than one environment like Production, Staging and Development for your application. You need specific Environment appsettings i.e., appsettings.{environment}.json.
Or if you don't want to use any specific environment. In this case you are using only production (Default) Environment you can use appsettings.json file.
Few reasons to use Azure Application Settings -
1st - Let's assume that in order to avoid leaking configurations in appsettings.json, you aren't committing it to your repo. But you also deploy your web app on Azure AppServices. In this situation Application Settings tab can help you to configure your configurations directly and then Azure will auto create appsettings.json by reading those values.
2nd - This time we are committing appsettings.json and deployed web app on Azure. We also have a property as
{
"Users": {
"CanAccessApp": [ "abc#gmail.com", "test#gmail.com" ],
"CanAccessHangfire": [ "abc#gmail.com", "test#gmail.com" ],
"CanAccessLog": [ "abc#gmail.com", "test#gmail.com" ]
}
}
Now, I also want one more user to be able to access logs. How you will do it? Generally, update in your appsettings.json and redeploy.
Or you can create similar property in Application Settings by
Users:CanAccessLog:0 -> vic#gmail.com
Users:CanAccessLog:1 -> abc#gmail.com
Users:CanAccessLog:2 -> test#gmail.com
and so on where 0,1,2 are indexes of the array (Azure style). This one will help us to test quickly without redeploying or modifying appsettings.json.
I have below below settings host.json for maxConcurrentSessions for Azure Function app service bus trigger.
"extensions": {
"serviceBus": {
"sessionHandlerOptions": {
"autoComplete": false,
"maxConcurrentSessions": 100
}
}
}
Can I set this host json configuration Function App configuration application settings like service bus connection string? if Yes, how?
Looking at the documentation, you can override settings defined in the host.json using appsettings:
There may be instances where you wish to configure or modify specific settings in a host.json file for a specific environment, without changing the host.json file itself. You can override specific host.json values by creating an equivalent value as an application setting. When the runtime finds an application setting in the format AzureFunctionsJobHost__path__to__setting, it overrides the equivalent host.json setting located at path.to.setting in the JSON. When expressed as an application setting, the dot (.) used to indicate JSON hierarchy is replaced by a double underscore (__).
So in you case defining an appsetting AzureFunctionsJobHost__extensions__serviceBus__sessionHandlerOptions__maxConcurrentSessions will do the trick.
I'm trying to track when my bot stops responding. I think it stops responding when it doesn't get any usage for a while. I'll send it a few requests sometimes and then I won't get any responses back. I can fix this by stopping and restarting the App Service within the Azure Portal.
I was considering creating a cronjob that sends a POST request to the somebotname.azurewebsites.net/api/messages endpoint and e-mailing me if there's no response, but I'm not sure how to get a token so that this will pass. I was also considering doing a daily publish via azure devops but I'm not sure if this is even possible.
Is there a best practice for testing if a bot is still running?
The best way to do it is with Application Insights which you can find here
https://learn.microsoft.com/en-us/azure/azure-monitor/app/app-insights-overview
It's not hard to add to a project. Simply add NuGet package and initialize with the key (InstrumentationKey).
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.7.0" />
</ItemGroup>
And init like so
public void ConfigureServices(IServiceCollection services)
{
// The following line enables Application Insights telemetry collection.
services.AddApplicationInsightsTelemetry();
// This code adds other services for your application.
services.AddMvc();
}
With appsettings.json
{
"ApplicationInsights": {
"InstrumentationKey": "putinstrumentationkeyhere"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
}
}
For instance here is full example for .NET core
https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core
In the app insights you will see all errors in real time and you can set up alerts to notify you of downtime.
If you will have production issues there is also cool feature of snapshot debugging to test what happened.
Check your "Always On" setting and make sure it's set to "On".
Azure WebSites Always On
Configuration->General Settings->Always On
Of course, you'll need to pay more in this case.
In the Azure portal I select my web app and then "Application settings" and it shows this:
An error message, "Failed to load settings", for application settings and also for connection strings.
How do I fix this?
Additional information:
Another user with the same privileges than me is also experiencing this issue when going to the same Application settings page. Also I'm able to deploy so I have the privilege to modify web.config
Additional information #2:
So I used Chrome Inspector as suggested and its trying to get application settings with a POST to https://management.azure.com/subscriptions/xxxxxxxxxxx/resourceGroups/xxx/providers/Microsoft.Web/sites/xxx/config/appSettings/list?api-version=2015-08-01
This is the JSON response:
{
"error": {
"code":"ReadOnlyDisabledSubscription",
"message":"The subscription 'xxxxxxxxxx' is disabled and therefore marked as read only. You cannot perform any write actions on this subscription until it is re-enabled."
}
}
Sometimes the Azure portal has bugs.
Also try https://preview.portal.azure.com, occasionally that works for me when the main portal has errors.