# Google Cloud Logging v2 API - Class ServiceCollectionExtensions (4.5.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [4.5.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)
- [4.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/4.4.0/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)
- [4.3.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/4.3.0/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)
- [4.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/4.2.0/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)
- [4.1.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/4.1.0/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)
- [4.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/4.0.0/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)
- [3.6.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/3.6.0/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)
- [3.5.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/3.5.0/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)
- [3.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/3.4.0/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)
- [3.3.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/3.3.0/Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions)

    public static class ServiceCollectionExtensions

Reference documentation and code samples for the Google Cloud Logging v2 API class ServiceCollectionExtensions.

Static class to provide extension methods to configure API clients.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> ServiceCollectionExtensions

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Microsoft.Extensions.DependencyInjection](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Microsoft.Extensions.DependencyInjection)

## Assembly

Google.Cloud.Logging.V2.dll

## Methods

### AddConfigServiceV2Client(IServiceCollection, Action\<ConfigServiceV2ClientBuilder\>)

    public static IServiceCollection AddConfigServiceV2Client(this IServiceCollection services, Action<ConfigServiceV2ClientBuilder> action = null)

Adds a singleton [ConfigServiceV2Client](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.ConfigServiceV2Client) to `services`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `services` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` The service collection to add the client to. The services are used to configure the client when requested. |
| `action` | `https://learn.microsoft.com/dotnet/api/system.action-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.ConfigServiceV2ClientBuilder` An optional action to invoke on the client builder. This is invoked before services from `services` are used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` |   |

### AddConfigServiceV2Client(IServiceCollection, Action\<IServiceProvider, ConfigServiceV2ClientBuilder\>)

    public static IServiceCollection AddConfigServiceV2Client(this IServiceCollection services, Action<IServiceProvider, ConfigServiceV2ClientBuilder> action)

Adds a singleton [ConfigServiceV2Client](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.ConfigServiceV2Client) to `services`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `services` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` The service collection to add the client to. The services are used to configure the client when requested. |
| `action` | `https://learn.microsoft.com/dotnet/api/system.action-2System.IServiceProviderhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.ConfigServiceV2ClientBuilder` An optional action to invoke on the client builder. This is invoked before services from `services` are used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` |   |

### AddLoggingServiceV2Client(IServiceCollection, Action\<LoggingServiceV2ClientBuilder\>)

    public static IServiceCollection AddLoggingServiceV2Client(this IServiceCollection services, Action<LoggingServiceV2ClientBuilder> action = null)

Adds a singleton [LoggingServiceV2Client](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LoggingServiceV2Client) to `services`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `services` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` The service collection to add the client to. The services are used to configure the client when requested. |
| `action` | `https://learn.microsoft.com/dotnet/api/system.action-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LoggingServiceV2ClientBuilder` An optional action to invoke on the client builder. This is invoked before services from `services` are used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` |   |

### AddLoggingServiceV2Client(IServiceCollection, Action\<IServiceProvider, LoggingServiceV2ClientBuilder\>)

    public static IServiceCollection AddLoggingServiceV2Client(this IServiceCollection services, Action<IServiceProvider, LoggingServiceV2ClientBuilder> action)

Adds a singleton [LoggingServiceV2Client](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LoggingServiceV2Client) to `services`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `services` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` The service collection to add the client to. The services are used to configure the client when requested. |
| `action` | `https://learn.microsoft.com/dotnet/api/system.action-2System.IServiceProviderhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LoggingServiceV2ClientBuilder` An optional action to invoke on the client builder. This is invoked before services from `services` are used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` |   |

### AddMetricsServiceV2Client(IServiceCollection, Action\<MetricsServiceV2ClientBuilder\>)

    public static IServiceCollection AddMetricsServiceV2Client(this IServiceCollection services, Action<MetricsServiceV2ClientBuilder> action = null)

Adds a singleton [MetricsServiceV2Client](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.MetricsServiceV2Client) to `services`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `services` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` The service collection to add the client to. The services are used to configure the client when requested. |
| `action` | `https://learn.microsoft.com/dotnet/api/system.action-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.MetricsServiceV2ClientBuilder` An optional action to invoke on the client builder. This is invoked before services from `services` are used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` |   |

### AddMetricsServiceV2Client(IServiceCollection, Action\<IServiceProvider, MetricsServiceV2ClientBuilder\>)

    public static IServiceCollection AddMetricsServiceV2Client(this IServiceCollection services, Action<IServiceProvider, MetricsServiceV2ClientBuilder> action)

Adds a singleton [MetricsServiceV2Client](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.MetricsServiceV2Client) to `services`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `services` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` The service collection to add the client to. The services are used to configure the client when requested. |
| `action` | `https://learn.microsoft.com/dotnet/api/system.action-2System.IServiceProviderhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.MetricsServiceV2ClientBuilder` An optional action to invoke on the client builder. This is invoked before services from `services` are used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` |   |