Skip to content

Windows Azure Websites Diagnostics Cmdlets

guangyang edited this page Apr 17, 2013 · 25 revisions

To be implemented


Table of Content

These cmdlets are designed in a similar pattern of Get-WinEvent.

Introduction to Azure Website Diagnostics

Windows Azure Websites has just enabled some new diagnostics features. It allows you to write application logs in .NET and Node.js applications into 2 different locations:

  • Azure Drive: a folder within Windows Azure Websites where logs are written into log files. This will
    • Enable different log paths, like application or http.
    • Enable path and full text matching.
    • Enable log streaming.
    • Only store at max 30MB logs.
    • Be automatically turned off every 12 hours.
  • Azure Table Storage: a table in some storage account where logs are written as table entities. This will enable
    • Enable store more logs.
    • Advanced query like query by log level and timestamp.
    • Only store application logs.

The logs contain following information: timestamp, application name, event id, event tick count, level, message, pid and tid.

Here we are adding a few new cmdlets to Windows Azure PowerShell to support these new Azure Website diagnostics features.

Notice that accessing Azure Table Storage can have a billing impact. So all the cmdlets which access Azure Table Storage have some default values set up to make sure no large bill will be generated.

Enable Azure Website Diagnostics

This cmdlet is used to enable site and application diagnostics for Azure Website.

Enable-AzureWebsiteDiagnostic -Type [<AzureWebsiteDiagnosticType> {Site | Application}]

Enable-AzureWebsiteDiagnostic -Type Site [-WebServerLogging [<SwitchParameter>]]
 [-DetailedErrorMessages [<SwitchParameter>]] [-FailedRequestTracing [<SwitchParameter>]]

Enable-AzureWebsiteDiagnostic -Type Application -Output [<AzureWebsiteDiagnosticOutput> {FileSystem | StorageTable}]
 [-LogLevel [<AzureWebsiteDiagnosticLogLevel> {Error | Warning | Information | Verbose}]]

Enable-AzureWebsiteDiagnostic -Type Application -Output FileSystem
 [-LogLevel [<AzureWebsiteDiagnosticLogLevel> {Error | Warning | Information | Verbose}]]

Enable-AzureWebsiteDiagnostic -Type Application -Output StorageTable
 [-LogLevel [<AzureWebsiteDiagnosticLogLevel>{Error | Warning | Information | Verbose}]]
 [-StorageAccountName <String>]
  • Parameters
    • -Type: Specifies what kind of diagnostics to enable Site or Application
  • Dynamic Parameters: Depends on the value of the -Type parameter, following are the dynamic parameters one can use
    • -Type Site: If no dynamic parameter is specified, the cmdlet will enable all three.
      • -WebServerLogging: Enables web server logging
      • -DetailedErrorMessages: Enables detailed error messages
      • -FailedRequestTracing: Enables failed request tracing
    • -Type Application
      • -Output: Specifies where to store the log. Supported values are FileSystem and StorageTable
        • -Output FileSysten: No further dynamic parameter
        • -Output StorageTable
          • -StorageAccountName: Specifies which storage account to store the log. If not specified, will use the current storage account of the subscription.
      • -LogLevel: Specifies the log level. Supported values are Error, Warning, Information and Verbose. By default is Error.
  • Output
  • Verbose

Notice that multiple calls to this cmdlet with different parameters won't overwrite each other. So the following 2 scripts are the same

# 1
Enable-AzureWebsiteDiagnostic -Type Site -WebServerLogging
Enable-AzureWebsiteDiagnostic -Type Site -DetailedErrorMessages

# 2
Enable-AzureWebsiteDiagnostic -Type Site -WebServerLogging -DetailedErrorMessages

Disable Azure Website Diagnostics

This cmdlet is used to disable site and application diagnostics for Azure Website.

Disable-AzureWebsiteDiagnostic -Type [<AzureWebsiteDiagnosticType> {Site | Application}]

Disable-AzureWebsiteDiagnostic -Type Site [-WebServerLogging [<SwitchParameter>]]
 [-DetailedErrorMessages [<SwitchParameter>]] [-FailedRequestTracing [<SwitchParameter>]]

Disable-AzureWebsiteDiagnostic -Type Application [-Output [<AzureWebsiteDiagnosticOutput> {FileSystem | StorageTable}]]
  • Parameters

    • -Type: Specifies what kind of diagnostics to disable Site or Application
  • Dynamic Parameters: Depends on the value of the -Type parameter, following are the dynamic parameters one can use

    • -Type Site: If no dynamic parameter is specified, the cmdlet will disable all three.
      • -WebServerLogging: Disables web server logging
      • -DetailedErrorMessages: Disables detailed error messages
      • -FailedRequestTracing: Disables failed request tracing
    • -Type Application
      • -Output: Specifies where to store the log. Supported values are FileSystem and StorageTable. If not specified, the cmdlet will disable both.
  • Output

  • Verbose

Notice that multiple calls to this cmdlet with different parameters won't overwrite each other. So the following 2 scripts are the same

# 1
Disable-AzureWebsiteDiagnostic -Type Site -WebServerLogging
Disable-AzureWebsiteDiagnostic -Type Site -DetailedErrorMessages

# 2
Disable-AzureWebsiteDiagnostic -Type Site -WebServerLogging -DetailedErrorMessages

View Azure Website Log

Get-AzureWebsiteLog [[-Max] <Int64>] [[-Level] <Int32[]>] [[-StartTime] <DateTime>] [[-EndTime] <DateTime>]
 [[-Message] <String>] [[-Name] <String>]
Get-AzureWebsiteLog [[-Level] <Int32[]>] [[-Path] <String[]>] [[-Message] <String>] [[-Name] <String>]
 [-Tail [<SwitchParameter>]]
Get-AzureWebsiteLog -ListPath [<SwitchParameter>]
  • Parameters
    • -Name: Specify the name of the website you want to export the logs. If not provided, it will try to find the website name from cwd if it's a repo. Otherwise, it will fail.
    • -Max: Specifies the maximum number of logs that this cmdlet returns. Enter an integer. The default is to return the latest 100 logs.
      • It only works when Azure Table Storage Diagnostics is enabled.
      • It cannot be used together with -Tail.
      • If it's used together with the query parameters (-Level, Path, -StartTime, -EndTime and -Message), the query parameters will always apply first.
    • Level <Int32[]>: Specifies the levels of the logs you want to get. You can provide a single integer or an array of integers which indicates the levels.
      • Default is all levels.
      • This parameter only works when Azure Table Storage Diagnostics is enabled.
    • Path <String[]>: Specify the paths of the logs you want to get.
      • Default is Root which means all the paths.
      • This parameter only works when Azure Drive Diagnostics is enabled.
    • StartTime <DateTime>: Specifies the start time of the logs you want. Notice that this parameter only works when Azure Table Storage Diagnostics is enabled.
    • EndTime <DateTime>: Specifies the end time of the logs you want. Notice that this parameter only works when Azure Table Storage Diagnostics is enabled.
    • Message <String>: Specifies a string which will be used to match the log message. Only the logs which include this string will be returned.
    • -Tail: Set this cmdlet to log streaming mode.
      • It only works when Azure Drive Diagnostics is enabled.
      • It cannot be used together with -Max.
    • -ListPath: P2 Gets the list of log paths for the website.
  • Output
2013-01-25T21:54:43  PID[8512] Error       sample error
2013-01-25T21:54:44  PID[8512] Warning     sample warning
2013-01-25T21:54:44  PID[8512] Information sample information
2013-01-25T21:54:44  PID[8512] Verbose     sample message
  • Verbose
  • Paging: Need to make sure this paging scenario works Get-AzureWebsiteLog | Out-Host -Paging

Download Azure Website Log

Save-AzureWebsiteLog [[-Output] <String>] [[-Source] <String>] [[-Name] <String>]
  • New Parameters
    • -Output: Specify where you want to put the exported logs.
    • -Source: Specify which log source you want to include. Possible values for now are azure storage and file drive. Notice that the names for the values may change.
    • -Name: Specify the name of the website you want to export the logs. If not provided, it will try to find the website name from cwd if it's a repo. Otherwise, it will fail.
  • Output
  • Verbose

P2: Clear Azure Website Log

Clear-AzureWebsiteLog [[-FilterHashtable] <Hashtable[]>] [[-Name] <String>] [-Force [<SwitchParameter>]]
  • Parameters
    • EndTime: Specifies the end time of the logs you want to delete. This parameter only works when Azure Table Storage Diagnostics is enabled.
    • -Name: Specify the name of the website you want to clear the logs. If not provided, it will try to find the website name from cwd if it's a repo. Otherwise, it will fail.
    • -Force: Force the cmdlet not to prompt for the operation.
  • Prompt: By default the cmdlet will prompt the user to confirm the operation.
  • Output
  • Verbose

References