# Class LoggerOptions (4.4.0)

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

- [4.4.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/4.3.1/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions)

    [Obsolete("Use Google.Cloud.Diagnostics.Common.LoggingOptions andGoogle.Cloud.Diagnostics.Common.LoggingServiceOptions instead.")]
    public sealed class LoggerOptions

Options for a [GoogleLogger](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.GoogleLogger).

## Inheritance

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

## Inherited Members

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

## Namespace

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

## Assembly

Google.Cloud.Diagnostics.AspNetCore.dll

## Properties

### BufferOptions

    public BufferOptions BufferOptions { get; }

The buffer options for the logger.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions.html` |   |

### Labels

    public Dictionary<string, string> Labels { get; }

Custom labels for log entries.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.dictionary-2<https://learn.microsoft.com/dotnet/api/system.string, https://learn.microsoft.com/dotnet/api/system.string>` |   |

**Remarks** Keys and values added to [Labels](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions#Google_Cloud_Diagnostics_AspNetCore_LoggerOptions_Labels) should not be null.
If they are, an exception will be throw when attempting to log an entry.
The entry won't be logged and the exception will be propagated depending
on the value of [ExceptionHandling](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions.html#Google_Cloud_Diagnostics_Common_RetryOptions_ExceptionHandling).

### LoggerDiagnosticsOutput

    public TextWriter LoggerDiagnosticsOutput { get; }

A [TextWriter](https://learn.microsoft.com/dotnet/api/system.io.textwriter) to write diagnostics info about loggers created
with these [LoggerOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions).
Currently the only diagnostics info we provide is the URL where the logs written
with these options can be found.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.io.textwriter` |   |

### LogLevel

    public LogLevel LogLevel { get; }

The minimum log level.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel` |   |

### LogName

    public string LogName { get; }

The name for the all logs.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### MonitoredResource

    public MonitoredResource MonitoredResource { get; }

The monitored resource. See: <https://cloud.google.com/logging/docs/api/v2/resource-list>

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html` |   |

### RetryOptions

    public RetryOptions RetryOptions { get; }

The retry options for the logger.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions.html` |   |

### ServiceName

    public string ServiceName { get; }

An identifier of the service, such as the name of the executable or job. May be null.
When set, it will be included in the

    serviceContext

field of the log entry JSON payload.

<br />

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### Version

    public string Version { get; }

A string that represents the version of the service or the source code that logs are written for.
When set, it will be included in the

    serviceContext

field of the log entry JSON payload.

<br />

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

## Methods

### Create(LogLevel, String, Dictionary\<String, String\>, MonitoredResource, BufferOptions, RetryOptions, TextWriter)

    public static LoggerOptions Create(LogLevel logLevel = LogLevel.Information, string logName = null, Dictionary<string, string> labels = null, MonitoredResource monitoredResource = null, BufferOptions bufferOptions = null, RetryOptions retryOptions = null, TextWriter loggerDiagnosticsOutput = null)

Create a new instance of [LoggerOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `logLevel` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel` Optional, the minimum log level. Defaults to [Information](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel#microsoft-extensions-logging-loglevel-information) |
| `logName` | `https://learn.microsoft.com/dotnet/api/system.string` Optional, the name of the log. Defaults to 'aspnetcore'. |
| `labels` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.dictionary-2<https://learn.microsoft.com/dotnet/api/system.string, https://learn.microsoft.com/dotnet/api/system.string>` Optional, custom labels to be added to log entries. Keys and values added to `labels` should not be null. If they are, an exception will be throw when attempting to log an entry. The entry won't be logged and the exception will be propagated depending on the value of [ExceptionHandling](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions.html#Google_Cloud_Diagnostics_Common_RetryOptions_ExceptionHandling). |
| `monitoredResource` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html` Optional, the monitored resource. The monitored resource will be automatically detected if it is not set and will default to the global resource if the detection fails. See: <https://cloud.google.com/logging/docs/api/v2/resource-list> |
| `bufferOptions` | `https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions.html` Optional, the buffer options. Defaults to a [Timed](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType.html#Google_Cloud_Diagnostics_Common_BufferType_Timed) |
| `retryOptions` | `https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions.html` Optional, the retry options. Defaults to a [None](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryType.html#Google_Cloud_Diagnostics_Common_RetryType_None) |
| `loggerDiagnosticsOutput` | `https://learn.microsoft.com/dotnet/api/system.io.textwriter` Optional. If set some logger diagnostics info will be written to the given [TextWriter](https://learn.microsoft.com/dotnet/api/system.io.textwriter). Currently the only diagnostics info we provide is the URL where the logs written with these options can be found. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions` |   |

### CreateWithDetectedServiceContext(LogLevel, String, Dictionary\<String, String\>, MonitoredResource, BufferOptions, RetryOptions, TextWriter)

    public static LoggerOptions CreateWithDetectedServiceContext(LogLevel logLevel = LogLevel.Information, string logName = null, Dictionary<string, string> labels = null, MonitoredResource monitoredResource = null, BufferOptions bufferOptions = null, RetryOptions retryOptions = null, TextWriter loggerDiagnosticsOutput = null)

Create a new instance of [LoggerOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions) with default service context.
If `monitoredResource` is provided, the service context will be obtained from it.
Else, if running on GAE, the service context will be obtained from the platform.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `logLevel` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel` Optional, the minimum log level. Defaults to [Information](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel#microsoft-extensions-logging-loglevel-information) |
| `logName` | `https://learn.microsoft.com/dotnet/api/system.string` Optional, the name of the log. Defaults to 'aspnetcore'. |
| `labels` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.dictionary-2<https://learn.microsoft.com/dotnet/api/system.string, https://learn.microsoft.com/dotnet/api/system.string>` Optional, custom labels to be added to log entries. Keys and values added to `labels` should not be null. If they are, an exception will be throw when attempting to log an entry. The entry won't be logged and the exception will be propagated depending on the value of [ExceptionHandling](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions.html#Google_Cloud_Diagnostics_Common_RetryOptions_ExceptionHandling). |
| `monitoredResource` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html` Optional, the monitored resource. The monitored resource will be automatically detected if it is not set and will default to the global resource if the detection fails. See: <https://cloud.google.com/logging/docs/api/v2/resource-list> |
| `bufferOptions` | `https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions.html` Optional, the buffer options. Defaults to a [Timed](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType.html#Google_Cloud_Diagnostics_Common_BufferType_Timed) |
| `retryOptions` | `https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions.html` Optional, the retry options. Defaults to a [None](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryType.html#Google_Cloud_Diagnostics_Common_RetryType_None) |
| `loggerDiagnosticsOutput` | `https://learn.microsoft.com/dotnet/api/system.io.textwriter` Optional. If set some logger diagnostics info will be written to the given [TextWriter](https://learn.microsoft.com/dotnet/api/system.io.textwriter). Currently the only diagnostics info we provide is the URL where the logs written with these options can be found. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions` |   |

### CreateWithServiceContext(LogLevel, String, Dictionary\<String, String\>, MonitoredResource, BufferOptions, RetryOptions, TextWriter, String, String)

    public static LoggerOptions CreateWithServiceContext(LogLevel logLevel = LogLevel.Information, string logName = null, Dictionary<string, string> labels = null, MonitoredResource monitoredResource = null, BufferOptions bufferOptions = null, RetryOptions retryOptions = null, TextWriter loggerDiagnosticsOutput = null, string serviceName = null, string version = null)

Create a new instance of [LoggerOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `logLevel` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel` Optional, the minimum log level. Defaults to [Information](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel#microsoft-extensions-logging-loglevel-information) |
| `logName` | `https://learn.microsoft.com/dotnet/api/system.string` Optional, the name of the log. Defaults to 'aspnetcore'. |
| `labels` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.dictionary-2<https://learn.microsoft.com/dotnet/api/system.string, https://learn.microsoft.com/dotnet/api/system.string>` Optional, custom labels to be added to log entries. Keys and values added to `labels` should not be null. If they are, an exception will be throw when attempting to log an entry. The entry won't be logged and the exception will be propagated depending on the value of [ExceptionHandling](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions.html#Google_Cloud_Diagnostics_Common_RetryOptions_ExceptionHandling). |
| `monitoredResource` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html` Optional, the monitored resource. The monitored resource will be automatically detected if it is not set and will default to the global resource if the detection fails. See: <https://cloud.google.com/logging/docs/api/v2/resource-list> |
| `bufferOptions` | `https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions.html` Optional, the buffer options. Defaults to a [Timed](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType.html#Google_Cloud_Diagnostics_Common_BufferType_Timed) |
| `retryOptions` | `https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions.html` Optional, the retry options. Defaults to a [None](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryType.html#Google_Cloud_Diagnostics_Common_RetryType_None) |
| `loggerDiagnosticsOutput` | `https://learn.microsoft.com/dotnet/api/system.io.textwriter` Optional. If set some logger diagnostics info will be written to the given [TextWriter](https://learn.microsoft.com/dotnet/api/system.io.textwriter). Currently the only diagnostics info we provide is the URL where the logs written with these options can be found. |
| `serviceName` | `https://learn.microsoft.com/dotnet/api/system.string` A string that represents the version of the service or the source code that logs are written for. When set, it will be included in the serviceContext field of the log entry JSON payload. <br /> |
| `version` | `https://learn.microsoft.com/dotnet/api/system.string` A string that represents the version of the service or the source code that logs are written for. When set, it will be included in the serviceContext field of the log entry JSON payload. <br /> |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.LoggerOptions` |   |