Skip to content

Windows Azure Websites Diagnostics Cmdlets

guangyang edited this page Mar 1, 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.

Configure Azure Website Diagnostics Settings

Set-AzureWebsite [-AzureDriveTraveEnabled [<Boolean>]] [-AzureTableTraceEnabled [<Boolean>]]
 [-AzureDriveTraceLevel <Int32>] [-AzureTableTraceLevel <Int32>]
  • New Parameters
    • -AzureDriveTraceEnabled: Determines whether writing logs to Azure Drive is enabled
    • -AzureDriveTraceLevel: Sets the trace level for Azure Drive diagnostics
    • -AzureTableTraceEnabled: Determines whether writing logs to Table Storage is enabled
    • -AzureTableTraceLevel: Sets the trace level of Azure Table diagnostics
  • Output
  • Verbose

The connection string of the Azure Storage account used by diagnostics can be configured via the existing -ConnectionStrings parameter.

View Azure Website Log

Get-AzureWebsiteLog [[-Max] <Int64>] [[-FilterHashtable] <Hashtable[]>] [[-Name] <String>]
Get-AzureWebsiteLog [[-FilterHashtable] <Hashtable[]>] [[-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 -FilterHashtable, -FilterHashtable will always apply first.
    • -FilterHashtable: Uses a query in hash table format to select logs. The query contains a hash table with one or more key-value pairs. Hash table queries have the following rules:
      • Keys and values are case-insensitive.
      • Each key can be listed only once in each hash-table.
      • Only support path and message string matching for Azure Drive Diagnostics
      • Support advanced query for Azure Table Storage Diagnostics
      • The valid key-value pairs are as follows:
        • LogLevel <Int32[]>: Specify 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.
        • LogPath <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.
    • -ListLogPath: 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>] [[-FilterHashtable] <Hashtable[]>]
 [[-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.
    • -FilterHashtable: P2 Uses a query in hash table format to select logs. The query contains a hash table with one or more key-value pairs. Hash table queries have the following rules:
      • Keys and values are case-insensitive.
      • Each key can be listed only once in each hash-table.
      • Only support path and message string matching for Azure Drive Diagnostics
      • Support advanced query for Azure Table Storage Diagnostics
      • The valid key-value pairs are as follows:
        • LogLevel <Int32[]>: Specify 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.
          • This parameter only works when Azure Table Storage Diagnostics is enabled.
        • LogPath <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.
          • Default value is DateTime.now.AddDays(-1).
          • This parameter only works when Azure Table Storage Diagnostics is enabled.
        • EndTime <DateTime>: Specifies the end time of the logs you want.
          • Default value is DateTime.now.
          • This parameter only works when Azure Table Storage Diagnostics is enabled.
    • -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
    • -FilterHashtable: Uses a query in hash table format to select logs. The query contains a hash table with one or more key-value pairs. Hash table queries have the following rules:
      • Keys and values are case-insensitive.
      • Each key can be listed only once in each hash-table.
      • Only support path and message string matching for Azure Drive Diagnostics
      • Support advanced query for Azure Table Storage Diagnostics
      • The valid key-value pairs are as follows:
        • StartTime: Specifies the start time of the logs you want.
          • Default value is DateTime.now.AddDays(-1).
          • This parameter only works when Azure Table Storage Diagnostics is enabled.
        • EndTime: Specifies the end time of the logs you want.
          • Default value is DateTime.now.
          • 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