I have an app service, on my dev environment I see that it generates about 1GB logs monthly, on production app service is connected to log analytics workspace and in usage it says that log managements it's almost 80GB monthly. In monitoring->insights I see that just one table in 79GB. Relevant table on dev environment is just slightly less than 1GB I'm new to azure, how can I check why the same code generate 80 times more log in log analytics workspace than without it ? Sum of request to app service is almost the same in both env.
To optimize your logs when you have enabled the App Insights on your App Service (Azure Functions .Net Core Stack), there are the few steps and workarounds I did to minimize the unnecessary logs as well as optimize the Cost:
host.json
to minimize the logs. Only the manual logging showing in the logs/terminal and function info log is not produced where the function result is shown in the browser.- Disable unneeded modules: Edit the ApplicationInsights.config to turn off collection modules which are not required.
- Disable telemetry dynamically: To disable telemetry conditionally and dynamically anywhere in the code, set the DisableTelemetry
flag on it using TelemetryConfiguration
instance.
This code sample prevents the sending of telemetry to Application Insights but not the automatic collection modules from colleting telemetry and in order to remove auto collection modules also, please refer this Microsoft Documentation.
- Customize Logs Collection:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information"
}
}
}
}
The following above configuration allows Application Insights to capture all Information
logs and severe warning
logs. To change this behavior, explicitly override the logging configuration for the provider ApplicationInsights
as shown below:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
}
}
There are few more techniques to manage the data volume used for telemetry data optimizing also like:
Also, Please visit my practical workarounds (Ref1, Ref2)to reduce the unnecessary logs and optimize the cost.
References: