# Google.Cloud.Diagnostics.Common - Class ILoggerExtensions (5.3.0)

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

- [5.3.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.ILoggerExtensions)
- [5.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.2.0/Google.Cloud.Diagnostics.Common.ILoggerExtensions)
- [5.1.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.1.0/Google.Cloud.Diagnostics.Common.ILoggerExtensions)
- [5.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.0.0/Google.Cloud.Diagnostics.Common.ILoggerExtensions)
- [4.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.4.0/Google.Cloud.Diagnostics.Common.ILoggerExtensions)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.3.1/Google.Cloud.Diagnostics.Common.ILoggerExtensions)

    public static class ILoggerExtensions

Reference documentation and code samples for the Google.Cloud.Diagnostics.Common class ILoggerExtensions.

Extensions for [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger) to allow augmenting the logged information with contextual data.
[GoogleLogger](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.GoogleLogger)" will add the information to the [LogEntry](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LogEntry.html) that is sent to
Google Cloud Logging.
For the consumption of other loggers, the information will be included in newly created scopes
at the moment of logging, in a format that all loggers should understand.

## Inheritance

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

## 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

[Google.Cloud.Diagnostics.Common](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common)

## Assembly

Google.Cloud.Diagnostics.Common.dll

## Methods

### WithAddedLabels(ILogger, IEnumerable\<KeyValuePair\<string, string\>\>)

    public static ILogger WithAddedLabels(this ILogger logger, IEnumerable<KeyValuePair<string, string>> labels)


Adds labels to the returned logger that may be included with every subsequent log.
How this information is included will depend on the actual `logger`.
[GoogleLogger](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.GoogleLogger)" will include this information in [Labels](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LogEntry.html#Google_Cloud_Logging_V2_LogEntry_Labels).
For the consumption of other loggers, the information will be included in newly created scopes
at the moment of logging, in a format that all loggers should understand.


If `logger` had already been augmented with labels, `labels`
will be added to the existing ones on the returned [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `logger` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger` |
| `labels` | ``https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1System.Collections.Generic.KeyValuePair`2https://learn.microsoft.com/dotnet/api/system.stringhttps://learn.microsoft.com/dotnet/api/system.string`` |

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

### WithAddedLabels(ILogger, params KeyValuePair\<string, string\>\[\])

    public static ILogger WithAddedLabels(this ILogger logger, params KeyValuePair<string, string>[] labels)


Adds labels to the returned logger that may be included with every subsequent log.
How this information is included will depend on the actual `logger`.
[GoogleLogger](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.GoogleLogger)" will include this information in [Labels](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LogEntry.html#Google_Cloud_Logging_V2_LogEntry_Labels).
For the consumption of other loggers, the information will be included in newly created scopes
at the moment of logging, in a format that all loggers should understand.


If `logger` had already been augmented with labels, `labels`
will be added to the existing ones on the returned [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `logger` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger` |
| `labels` | ``System.Collections.Generic.KeyValuePair`2https://learn.microsoft.com/dotnet/api/system.stringhttps://learn.microsoft.com/dotnet/api/system.string`` |

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

### WithLabels(ILogger, IEnumerable\<KeyValuePair\<string, string\>\>)

    public static ILogger WithLabels(this ILogger logger, IEnumerable<KeyValuePair<string, string>> labels)


Adds labels to the returned logger that may be included with every subsequent log.
How this information is included will depend on the actual `logger`.
[GoogleLogger](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.GoogleLogger)" will include this information in [Labels](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LogEntry.html#Google_Cloud_Logging_V2_LogEntry_Labels).
For the consumption of other loggers, the information will be included in newly created scopes
at the moment of logging, in a format that all loggers should understand.


If `logger` had already been augmented with labels, the old labels will be replaced
by the new ones on the returned [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `logger` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger` |
| `labels` | ``https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1System.Collections.Generic.KeyValuePair`2https://learn.microsoft.com/dotnet/api/system.stringhttps://learn.microsoft.com/dotnet/api/system.string`` |

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

### WithLabels(ILogger, params KeyValuePair\<string, string\>\[\])

    public static ILogger WithLabels(this ILogger logger, params KeyValuePair<string, string>[] labels)


Adds labels to the returned logger that may be included with every subsequent log.
How this information is included will depend on the actual `logger`.
[GoogleLogger](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.GoogleLogger)" will include this information in [Labels](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LogEntry.html#Google_Cloud_Logging_V2_LogEntry_Labels).
For the consumption of other loggers, the information will be included in newly created scopes
at the moment of logging, in a format that all loggers should understand.


If `logger` had already been augmented with labels, the old labels will be replaced
by the new ones on the returned [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `logger` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger` |
| `labels` | ``System.Collections.Generic.KeyValuePair`2https://learn.microsoft.com/dotnet/api/system.stringhttps://learn.microsoft.com/dotnet/api/system.string`` |

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