Editar

Compartilhar via


New-AzApiManagementDiagnostic

Creates a new diagnostics at the Global scope or Api Scope.

Syntax

New-AzApiManagementDiagnostic
   -Context <PsApiManagementContext>
   -LoggerId <String>
   [-DiagnosticId <String>]
   [-AlwaysLog <String>]
   [-ApiId <String>]
   [-SamplingSetting <PsApiManagementSamplingSetting>]
   [-FrontEndSetting <PsApiManagementPipelineDiagnosticSetting>]
   [-BackendSetting <PsApiManagementPipelineDiagnosticSetting>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

The cmdlet New-AzApiManagementDiagnostic creates a diagnostic entity either at Global scope or specific Api scope.

Examples

Example 1: Create a new Global scope Diagnostic

$context = New-AzApiManagementContext -ResourceGroupName "Api-Default-WestUS" -ServiceName "contoso"
$logger = Get-AzApiManagementLogger -Context $context -LoggerId "backendapisachinc"
$samplingsetting = New-AzApiManagementSamplingSetting -SamplingType fixed -SamplingPercentage 100
New-AzApiManagementDiagnostic -LoggerId $logger.LoggerId -Context $context -AlwaysLog allErrors -SamplingSetting $samplingSetting  -DiagnosticId "applicationinsights"

DiagnosticId                 : applicationinsights
ApiId                        :
AlwaysLog                    : allErrors
LoggerId                     : backendapisachinc
EnableHttpCorrelationHeaders : True
SamplingSetting              : Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementSamplingSetting
FrontendSetting              :
BackendSetting               :
Id                           : /subscriptions/subid/resourceGroups/Api-Default-WestUs/providers/Microsoft.ApiManagement/service/contoso/diagnostics/applicationinsights
ResourceGroupName            : Api-Default-WestUs
ServiceName                  : contoso

This example create a diagnostic entity at the Global Scope.

Example 2: Create a diagnostic at Api scope

$context = New-AzApiManagementContext -ResourceGroupName "Api-Default-WestUS" -ServiceName "contoso"
$logger = Get-AzApiManagementLogger -Context $context -LoggerId azuremonitor
$samplingsetting = New-AzApiManagementSamplingSetting -SamplingType fixed -SamplingPercentage 100
$httpMessageDiagnostic = New-AzApiManagementHttpMessageDiagnostic -HeadersToLog 'Content-Type', 'User-Agent' -BodyBytesToLog 100
$pipelineDiagnostic = New-AzApiManagementPipelineDiagnosticSetting -Request $httpMessageDiagnostic -Response $httpMessageDiagnostic
New-AzApiManagementDiagnostic -LoggerId $logger.LoggerId -Context $context -ApiId httpbin -AlwaysLog allErrors -SamplingSetting $samplingsetting -FrontEndSetting $pipelineDiagnostic -BackendSetting $pipelineDiagnostic -DiagnosticId azuremonitor

DiagnosticId                 : azuremonitor
ApiId                        : httpbin
AlwaysLog                    : allErrors
LoggerId                     : azuremonitor
EnableHttpCorrelationHeaders :
SamplingSetting              : Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementSamplingSetting
FrontendSetting              : Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementPipelineDiagnosticSetting
BackendSetting               : Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementPipelineDiagnosticSetting
Id                           : /subscriptions/subid/resourceGroups/Api-Default-WestUS/providers/Microsoft.ApiManagement/service/contoso/apis/httpbin/diagnostics/azuremonitor      
ResourceGroupName            : Api-Default-WestUS
ServiceName                  : contoso

The example above create a diagnostic for the API httpbin to log the Header and 100 Bytes of Body to azuremonitor logger.

Parameters

-AlwaysLog

Specifies for what type of messages sampling settings should not apply. This parameter is optional.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-ApiId

Identifier of existing API. If specified will set API-scope policy. This parameters is required.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-BackendSetting

Diagnostic setting for incoming/outgoing Http Messages to the Backend. This parameter is optional.

Type:PsApiManagementPipelineDiagnosticSetting
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Context

Instance of PsApiManagementContext. This parameter is required.

Type:PsApiManagementContext
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DiagnosticId

Identifier of the diagnostics entity. This parameter is optional.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-FrontEndSetting

Diagnostic setting for incoming/outgoing Http Messages to the Gateway. This parameter is optional.

Type:PsApiManagementPipelineDiagnosticSetting
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-LoggerId

Identifier of the logger to push diagnostics to. This parameter is required.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-SamplingSetting

Sampling Setting of the Diagnostic. This parameter is optional.

Type:PsApiManagementSamplingSetting
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

PsApiManagementContext

String

PsApiManagementSamplingSetting

PsApiManagementPipelineDiagnosticSetting

Outputs

PsApiManagementDiagnostic