Bird
Raised Fist0
Azurecloud~5 mins

App Service diagnostics and logging in Azure - Commands & Configuration

Choose your learning style10 modes available
Introduction
When your web app has problems or you want to see how it behaves, you need to collect information about its activity and errors. App Service diagnostics and logging help you capture this information so you can understand and fix issues quickly.
When your web app is not responding or crashes unexpectedly and you want to find out why.
When you want to monitor the usage and performance of your app over time.
When you need to keep a record of errors and warnings for troubleshooting.
When you want to see detailed request and response logs to analyze traffic patterns.
When you want to enable diagnostics to get automatic suggestions from Azure about your app health.
Config File - diagnostics-settings.json
diagnostics-settings.json
{
  "kind": "web",
  "properties": {
    "logs": {
      "applicationLogs": {
        "fileSystem": {
          "level": "Information"
        }
      },
      "httpLogs": {
        "fileSystem": {
          "enabled": true,
          "retentionInDays": 7
        }
      },
      "detailedErrorMessages": {
        "enabled": true
      },
      "failedRequestTracing": {
        "enabled": true
      }
    }
  }
}

This JSON configures diagnostics for an Azure App Service web app.

  • applicationLogs.fileSystem.level: Captures app logs at Information level and above.
  • httpLogs.fileSystem.enabled: Turns on logging of HTTP requests to the file system.
  • httpLogs.fileSystem.retentionInDays: Keeps logs for 7 days before deleting.
  • detailedErrorMessages.enabled: Enables detailed error pages for easier debugging.
  • failedRequestTracing.enabled: Captures detailed traces of failed requests for deep troubleshooting.
Commands
This command enables application logging to the file system, detailed error messages, failed request tracing, and web server logging with a retention period of 7 days for the Azure App Service named 'example-app' in resource group 'example-rg'.
Terminal
az webapp log config --name example-app --resource-group example-rg --application-logging filesystem --detailed-error-messages true --failed-request-tracing true --web-server-logging filesystem --retention 7
Expected OutputExpected
Updated logging configuration for webapp example-app
→
--application-logging - Enables application logs to be saved to the file system.
→
--detailed-error-messages - Enables detailed error messages for easier debugging.
→
--failed-request-tracing - Enables tracing of failed HTTP requests.
This command streams the live logs from the 'example-app' web app so you can watch logs in real time as the app runs.
Terminal
az webapp log tail --name example-app --resource-group example-rg
Expected OutputExpected
Connecting to log stream... [2024-06-01T12:00:00] INFO Starting up example-app [2024-06-01T12:00:05] ERROR Unhandled exception occurred [2024-06-01T12:00:10] INFO Request processed successfully
This command shows the current logging configuration for the 'example-app' web app to verify what logs are enabled.
Terminal
az webapp log show --name example-app --resource-group example-rg
Expected OutputExpected
{ "applicationLogs": { "fileSystem": { "level": "Information" } }, "detailedErrorMessages": { "enabled": true }, "failedRequestTracing": { "enabled": true }, "httpLogs": { "fileSystem": { "enabled": true, "retentionInDays": 7 } } }
Key Concept

If you remember nothing else from this pattern, remember: enabling and viewing logs helps you quickly find and fix problems in your web app.

Common Mistakes
Not enabling the file system logging before trying to view logs.
Without enabling logging, no logs are saved or streamed, so you see no useful information.
Always run the log configuration command to enable logging before trying to view or stream logs.
Setting log retention to zero or not setting it at all.
Logs get deleted immediately or too soon, losing valuable diagnostic data.
Set a reasonable retention period like 7 days to keep logs available for troubleshooting.
Trying to stream logs from a web app that is stopped or not running.
No logs are generated if the app is not running, so the log stream will be empty.
Ensure the web app is running before streaming logs.
Summary
Use 'az webapp log config' to enable application, HTTP, and error logging with retention settings.
Use 'az webapp log tail' to stream live logs and watch your app's behavior in real time.
Use 'az webapp log show' to check the current logging configuration and verify settings.

Practice

(1/5)
1. What is the main purpose of enabling diagnostics and logging in Azure App Service?
easy
A. To increase the app's performance automatically
B. To monitor and troubleshoot the app's behavior and errors
C. To deploy new versions of the app faster
D. To secure the app from unauthorized access

Solution

  1. Step 1: Understand diagnostics and logging purpose

    Diagnostics and logging help capture app events and errors for monitoring.
  2. Step 2: Identify the main goal

    The main goal is to see what happens inside the app to fix issues.
  3. Final Answer:

    To monitor and troubleshoot the app's behavior and errors -> Option B
  4. Quick Check:

    Diagnostics = Monitor & troubleshoot [OK]
Hint: Think: Why watch app logs? To find and fix problems [OK]
Common Mistakes:
  • Confusing logging with performance tuning
  • Thinking logging deploys app updates
  • Assuming logging secures the app
2. Which Azure CLI command correctly enables application logging for an App Service named myapp with file system logging?
easy
A. az webapp log config --name myapp --resource-group mygroup --application-logging filesystem --level Information
B. az webapp log enable --name myapp --resource-group mygroup --application-logging filesystem
C. az appservice log config --app myapp --group mygroup --enable-logging filesystem
D. az webapp logging config --app myapp --resource-group mygroup --log-type filesystem

Solution

  1. Step 1: Identify correct Azure CLI syntax for logging

    The correct command uses az webapp log config with parameters for name, resource group, logging type, and level.
  2. Step 2: Match command to options

    az webapp log config --name myapp --resource-group mygroup --application-logging filesystem --level Information matches the correct syntax and parameters exactly.
  3. Final Answer:

    az webapp log config --name myapp --resource-group mygroup --application-logging filesystem --level Information -> Option A
  4. Quick Check:

    Correct CLI syntax = az webapp log config --name myapp --resource-group mygroup --application-logging filesystem --level Information [OK]
Hint: Use 'az webapp log config' with --application-logging and --level [OK]
Common Mistakes:
  • Using wrong command like 'az webapp log enable'
  • Mixing parameter names like --app instead of --name
  • Omitting the logging level parameter
3. Given the command az webapp log tail --name myapp --resource-group mygroup, what will be the output?
medium
A. It streams the live application logs from the App Service named myapp
B. It shows the last 10 deployment logs for myapp
C. It enables logging for the app myapp
D. It downloads the log files to local machine

Solution

  1. Step 1: Understand the purpose of 'az webapp log tail'

    This command streams live logs from the running app in real time.
  2. Step 2: Compare options to command behavior

    It streams the live application logs from the App Service named myapp correctly describes live log streaming, others describe different actions.
  3. Final Answer:

    It streams the live application logs from the App Service named myapp -> Option A
  4. Quick Check:

    Log tail = live streaming logs [OK]
Hint: Remember 'log tail' means live log streaming [OK]
Common Mistakes:
  • Thinking it shows deployment logs only
  • Confusing enabling logs with streaming logs
  • Assuming it downloads logs instead of streaming
4. You ran az webapp log config --name myapp --resource-group mygroup --application-logging filesystem --level Error but logs are not appearing. What is a likely cause?
medium
A. The app is not generating any error logs to capture
B. The command syntax is incorrect and did not apply settings
C. The resource group name is invalid
D. You forgot to enable web server logging separately

Solution

  1. Step 1: Check if web server logging is required

    Application logging and web server logging are separate; enabling one does not enable the other.
  2. Step 2: Identify missing step

    If web server logs are needed, they must be enabled explicitly; otherwise logs may not appear.
  3. Final Answer:

    You forgot to enable web server logging separately -> Option D
  4. Quick Check:

    Separate enable for web server logs needed [OK]
Hint: Enable both app and web server logging to see all logs [OK]
Common Mistakes:
  • Assuming application logging alone shows all logs
  • Ignoring separate logging types in Azure App Service
  • Blaming command syntax without checking logs generated
5. You want to diagnose a performance issue in your Azure App Service. Which combination of logging and diagnostic features should you enable to get detailed error messages, HTTP request logs, and live monitoring?
hard
A. Enable only detailed error messages without any logging
B. Enable only application logging to blob storage and disable web server logging
C. Enable application logging (filesystem), web server logging, and use az webapp log tail for live streaming
D. Use az webapp log download without enabling any logging

Solution

  1. Step 1: Identify needed logs for performance diagnosis

    Detailed error messages, HTTP request logs, and live monitoring require application logging, web server logging, and live log streaming.
  2. Step 2: Match features to options

    Enable application logging (filesystem), web server logging, and use az webapp log tail for live streaming enables all needed logs and live streaming for real-time diagnosis.
  3. Final Answer:

    Enable application logging (filesystem), web server logging, and use az webapp log tail for live streaming -> Option C
  4. Quick Check:

    Combine logs + live tail for full diagnosis [OK]
Hint: Combine app + web server logs with live tail for best insight [OK]
Common Mistakes:
  • Relying on only one type of logging
  • Not using live log streaming for real-time issues
  • Downloading logs without enabling logging first
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard