# AzureApplicationInsightsExtensions Methods

- Package: [Aspire.Hosting.Azure.ApplicationInsights](/reference/api/csharp/aspire.hosting.azure.applicationinsights.md)
- Type: [AzureApplicationInsightsExtensions](/reference/api/csharp/aspire.hosting.azure.applicationinsights/azureapplicationinsightsextensions.md)
- Kind: `Methods`
- Members: `4`

Provides extension methods for adding the Azure ApplicationInsights resources to the application model.

## AddAzureApplicationInsights(IDistributedApplicationBuilder, string)

- Name: `AddAzureApplicationInsights(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApplicationInsightsResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ApplicationInsights/AzureApplicationInsightsExtensions.cs#L26)

Adds an Azure Application Insights resource to the application model.

```csharp
public static class AzureApplicationInsightsExtensions
{
    public static IResourceBuilder<AzureApplicationInsightsResource> AddAzureApplicationInsights(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name of the resource. This name will be used as the connection string name when referenced in a dependency.

## Returns

`IResourceBuilder<AzureApplicationInsightsResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddAzureApplicationInsights(IDistributedApplicationBuilder, string, IResourceBuilder<AzureLogAnalyticsWorkspaceResource>)

- Name: `AddAzureApplicationInsights(IDistributedApplicationBuilder, string, IResourceBuilder<AzureLogAnalyticsWorkspaceResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApplicationInsightsResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ApplicationInsights/AzureApplicationInsightsExtensions.cs#L42-L125)

Adds an Azure Application Insights resource to the application model.

```csharp
public static class AzureApplicationInsightsExtensions
{
    public static IResourceBuilder<AzureApplicationInsightsResource> AddAzureApplicationInsights(
        this IDistributedApplicationBuilder builder,
        string name,
        IResourceBuilder<AzureLogAnalyticsWorkspaceResource>? logAnalyticsWorkspace)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name of the resource. This name will be used as the connection string name when referenced in a dependency.
- `logAnalyticsWorkspace` (`IResourceBuilder<AzureLogAnalyticsWorkspaceResource>`)
  A resource builder for the log analytics workspace.

## Returns

`IResourceBuilder<AzureApplicationInsightsResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This overload is not available in polyglot app hosts. Use [AzureApplicationInsightsExtensions.AddAzureApplicationInsights(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting.azure.applicationinsights/azureapplicationinsightsextensions/methods.md#addazureapplicationinsights-idistributedapplicationbuilder-string) and [AzureApplicationInsightsExtensions.WithLogAnalyticsWorkspace(IResourceBuilder<AzureApplicationInsightsResource>, BicepOutputReference)](/reference/api/csharp/aspire.hosting.azure.applicationinsights/azureapplicationinsightsextensions/methods.md#withloganalyticsworkspace-iresourcebuilder-azureapplicationinsightsresource-bicepoutputreference) instead.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithLogAnalyticsWorkspace(IResourceBuilder<AzureApplicationInsightsResource>, BicepOutputReference)

- Name: `WithLogAnalyticsWorkspace(IResourceBuilder<AzureApplicationInsightsResource>, BicepOutputReference)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApplicationInsightsResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ApplicationInsights/AzureApplicationInsightsExtensions.cs#L140)

Configures the Application Insights resource to use an existing Log Analytics Workspace via a `Azure.BicepOutputReference`.

```csharp
public static class AzureApplicationInsightsExtensions
{
    public static IResourceBuilder<AzureApplicationInsightsResource> WithLogAnalyticsWorkspace(
        this IResourceBuilder<AzureApplicationInsightsResource> builder,
        BicepOutputReference workspaceId)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApplicationInsightsResource>`)
  The resource builder for [AzureApplicationInsightsResource](/reference/api/csharp/aspire.hosting.azure.applicationinsights/azureapplicationinsightsresource.md).
- `workspaceId` (`BicepOutputReference`)
  The `Azure.BicepOutputReference` for the Log Analytics Workspace resource id.

## Returns

`IResourceBuilder<AzureApplicationInsightsResource>` -- The `ApplicationModel.IResourceBuilder`1` for chaining.

## Remarks

This overload is not available in polyglot app hosts. Use the overload that accepts an `ApplicationModel.IResourceBuilder`1` instead.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithLogAnalyticsWorkspace(IResourceBuilder<AzureApplicationInsightsResource>, IResourceBuilder<AzureLogAnalyticsWorkspaceResource>)

- Name: `WithLogAnalyticsWorkspace(IResourceBuilder<AzureApplicationInsightsResource>, IResourceBuilder<AzureLogAnalyticsWorkspaceResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureApplicationInsightsResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ApplicationInsights/AzureApplicationInsightsExtensions.cs#L155)

Configures the Application Insights resource to use the specified Log Analytics Workspace resource.

```csharp
public static class AzureApplicationInsightsExtensions
{
    public static IResourceBuilder<AzureApplicationInsightsResource> WithLogAnalyticsWorkspace(
        this IResourceBuilder<AzureApplicationInsightsResource> builder,
        IResourceBuilder<AzureLogAnalyticsWorkspaceResource> logAnalyticsWorkspace)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureApplicationInsightsResource>`)
  The resource builder for [AzureApplicationInsightsResource](/reference/api/csharp/aspire.hosting.azure.applicationinsights/azureapplicationinsightsresource.md).
- `logAnalyticsWorkspace` (`IResourceBuilder<AzureLogAnalyticsWorkspaceResource>`)
  The resource builder for the `Azure.AzureLogAnalyticsWorkspaceResource`.

## Returns

`IResourceBuilder<AzureApplicationInsightsResource>` -- The `ApplicationModel.IResourceBuilder`1` for chaining.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
