# Google.Cloud.Logging.NLog - Class GoogleStackdriverTarget (6.1.0)

6.1.0 (latest) 6.0.0 5.2.0 5.1.0 5.0.0 4.0.0 3.3.0

    [Target("GoogleStackdriver")]
    public class GoogleStackdriverTarget : TargetWithContext, IDisposable

Reference documentation and code samples for the Google.Cloud.Logging.NLog class GoogleStackdriverTarget.

Appends logging events to Google Stackdriver Logging.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> NLog.Targets.Target \> NLog.Targets.TargetWithLayout \> NLog.Targets.TargetWithContext \> GoogleStackdriverTarget

## Implements

[IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

## Inherited Members

NLog.Targets.TargetWithContext.ShouldIncludeProperties(NLog.LogEventInfo) NLog.Targets.TargetWithContext.GetContextProperties(NLog.LogEventInfo) [TargetWithContext.GetContextProperties(LogEventInfo, IDictionary\<string, object\>)](https://learn.microsoft.com/dotnet/api/system.collections.generic.idictionary-2) NLog.Targets.TargetWithContext.GetAllProperties(NLog.LogEventInfo) [TargetWithContext.GetAllProperties(LogEventInfo, IDictionary\<string, object\>)](https://learn.microsoft.com/dotnet/api/system.collections.generic.idictionary-2) [TargetWithContext.GenerateUniqueItemName(LogEventInfo, string, object, IDictionary\<string, object\>)](https://learn.microsoft.com/dotnet/api/system.string) NLog.Targets.TargetWithContext.GetScopeContextProperties(NLog.LogEventInfo) NLog.Targets.TargetWithContext.GetScopeContextNested(NLog.LogEventInfo) [TargetWithContext.CaptureContextGdc(LogEventInfo, IDictionary\<string, object\>)](https://learn.microsoft.com/dotnet/api/system.collections.generic.idictionary-2) [TargetWithContext.CaptureScopeContextProperties(LogEventInfo, IDictionary\<string, object\>)](https://learn.microsoft.com/dotnet/api/system.collections.generic.idictionary-2) [TargetWithContext.SerializeScopeContextProperty(LogEventInfo, string, object, out object)](https://learn.microsoft.com/dotnet/api/system.string) NLog.Targets.TargetWithContext.CaptureScopeContextNested(NLog.LogEventInfo) [TargetWithContext.SerializeScopeContextNestedState(LogEventInfo, object, out object)](https://learn.microsoft.com/dotnet/api/system.object) [TargetWithContext.SerializeItemValue(LogEventInfo, string, object, out object)](https://learn.microsoft.com/dotnet/api/system.string) NLog.Targets.TargetWithContext.Layout NLog.Targets.TargetWithContext.IncludeEventProperties NLog.Targets.TargetWithContext.IncludeScopeProperties NLog.Targets.TargetWithContext.IncludeScopeNested NLog.Targets.TargetWithContext.IncludeGdc NLog.Targets.TargetWithContext.IncludeCallSite NLog.Targets.TargetWithContext.IncludeCallSiteStackTrace NLog.Targets.TargetWithContext.ExcludeProperties NLog.Targets.Target.Dispose() NLog.Targets.Target.Flush(NLog.Common.AsyncContinuation) NLog.Targets.Target.PrecalculateVolatileLayouts(NLog.LogEventInfo) NLog.Targets.Target.ToString() NLog.Targets.Target.WriteAsyncLogEvent(NLog.Common.AsyncLogEventInfo) NLog.Targets.Target.WriteAsyncLogEvents(params NLog.Common.AsyncLogEventInfo\[\]) [Target.WriteAsyncLogEvents(IList\<AsyncLogEventInfo\>)](https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1) [Target.WriteFailedNotInitialized(AsyncLogEventInfo, Exception)](https://learn.microsoft.com/dotnet/api/system.exception) [Target.Dispose(bool)](https://learn.microsoft.com/dotnet/api/system.boolean) NLog.Targets.Target.Write(NLog.LogEventInfo) NLog.Targets.Target.WriteAsyncThreadSafe(NLog.Common.AsyncLogEventInfo) [Target.WriteAsyncThreadSafe(IList\<AsyncLogEventInfo\>)](https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1) NLog.Targets.Target.RenderLogEvent(NLog.Layouts.Layout, NLog.LogEventInfo) NLog.Targets.Target.RenderLogEvent\<T\>(NLog.Layouts.Layout\<T\>, NLog.LogEventInfo, T) NLog.Targets.Target.ResolveService\<T\>() NLog.Targets.Target.Name NLog.Targets.Target.SyncRoot NLog.Targets.Target.LoggingConfiguration NLog.Targets.Target.IsInitialized [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)

## Namespace

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

## Assembly

Google.Cloud.Logging.NLog.dll

## Constructors

### GoogleStackdriverTarget()

    public GoogleStackdriverTarget()

Construct a Google Cloud loggin target.

## Properties

### ContextProperties

    [ArrayParameter(typeof(TargetPropertyWithContext), "contextproperty")]
    public override IList<TargetPropertyWithContext> ContextProperties { get; }

Gets the array of custom attributes to be passed into the logevent context

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1NLog.Targets.TargetPropertyWithContext` |   |

**Overrides** NLog.Targets.TargetWithContext.ContextProperties

### CredentialFile

    public Layout CredentialFile { get; set; }

The file path of a service account JSON file to use for authentication.
Not necessary if running on GCE, GAE or GKE, or if the GOOGLE_APPLICATION_CREDENTIALS environment variable has been set.
Must not be set if [CredentialJson](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_CredentialJson) is set.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

### CredentialJson

    public Layout CredentialJson { get; set; }

JSON credential for authentication.
Not necessary if running on GCE or GAE or if the GOOGLE_APPLICATION_CREDENTIALS environment variable has been set.
Must not be set if [CredentialFile](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_CredentialFile) is set.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

### CredentialType

    public Layout CredentialType { get; set; }

The type of credential to load when either [CredentialFile](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_CredentialFile) or [CredentialJson](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_CredentialJson) is specified.
Valid strings can be found in the [JsonCredentialParameters](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.JsonCredentialParameters.html) class.
Defaults to [ServiceAccountCredentialType](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.JsonCredentialParameters.html#Google_Apis_Auth_OAuth2_JsonCredentialParameters_ServiceAccountCredentialType). Must not be null.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

### DisableResourceTypeDetection

    public bool DisableResourceTypeDetection { get; set; }

If set, disables resource-type detection based on platform,
so ResourceType will default to "global" if not manually set.

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

### EnableJsonLayout

    public bool EnableJsonLayout { get; set; }

Fills [JsonPayload](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LogEntry.html#Google_Cloud_Logging_V2_LogEntry_JsonPayload) in specified by user way with NLog.Layouts.JsonLayout layout type.
JSON values serialization can be customized using [JsonConverterTypeName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverterTypeName) and [JsonConverterMethodName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverterMethodName),
or [JsonConverter](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverter).

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

### JsonConverter

    public Func<object, Value> JsonConverter { get; set; }

When [SendJsonPayload](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_SendJsonPayload) is `true`, a custom JSON serialization method may be programatically specified here.
Must not be set if [JsonConverterTypeName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverterTypeName) and [JsonConverterMethodName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverterMethodName) are set.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.func-2https://learn.microsoft.com/dotnet/api/system.objecthttps://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Value.html` |   |

### JsonConverterMethodName

    public string JsonConverterMethodName { get; set; }

When [SendJsonPayload](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_SendJsonPayload) is `true`, a custom JSON serialization method may be specified by
type-name and method-name. Specify the type-name in [JsonConverterTypeName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverterTypeName), and the method-name here.
The instance or static method must have the signature `Value MyMethod(object obj)` or `JToken MyMethod(object o)`.
Must not be set if [JsonConverter](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverter) is set.

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

### JsonConverterTypeName

    public string JsonConverterTypeName { get; set; }

When [SendJsonPayload](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_SendJsonPayload) is `true`, a custom JSON serialization method may be specified by
type-name and method-name. Specify the type-name here, and the method-name in [JsonConverterMethodName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverterMethodName).
The instance or static method must have the signature `Value MyMethod(object obj)` or `JToken MyMethod(object o)`.
Must not be set if [JsonConverter](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverter) is set.

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

### LogId

    public Layout LogId { get; set; }

LogID for all log entries. Defaults to "Default".

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

### ProjectId

    public Layout ProjectId { get; set; }

The project ID for all log entries.
Must be configured if not executing on Google Compute Engine, Google App Engine or Google Kubernetes Engine.
If running on GCE, GAE or GKE, the ProjectId will be automatically detected if not set.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

### ResourceLabels

    [ArrayParameter(typeof(TargetPropertyWithContext), "resourcelabel")]
    public IList<TargetPropertyWithContext> ResourceLabels { get; }

Specify labels for the resource type;
only used if platform detection is disabled or detects an unknown platform.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1NLog.Targets.TargetPropertyWithContext` |   |

### ResourceType

    public string ResourceType { get; set; }

The resource type of log entries.
Default value depends on the detected platform. See the remarks section for details.

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

**Remarks** If this is not set, then Resource type is set depending on the detected execution platform:

- Google App Engine: ResourceType "gae_app", with project_id, module_id, and version_id set approprately.
- Google Compute Engine: ResourceType "gce_instance", with project_id, instance_id, and zone set approprately.
- Google Kubernetes Engine: ResourceType "container", with project_id and other labels set approprately.
- Unknown: ResourceType "global", with project_id set from this configuration.

If [DisableResourceTypeDetection](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_DisableResourceTypeDetection) is `true`, then this platform detection
is not performed, and this ResourceType defaults to "global" if not set.

### SendJsonPayload

    public bool SendJsonPayload { get; set; }

Fills [JsonPayload](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LogEntry.html#Google_Cloud_Logging_V2_LogEntry_JsonPayload) instead of [TextPayload](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LogEntry.html#Google_Cloud_Logging_V2_LogEntry_TextPayload).
JSON values serialization can be customized using [JsonConverterTypeName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverterTypeName) and [JsonConverterMethodName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverterMethodName),
or [JsonConverter](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_JsonConverter).

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

### ServiceContextName

    public Layout ServiceContextName { get; set; }

Configures "service" for the "serviceContext" when [SendJsonPayload](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_SendJsonPayload) = true

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

### ServiceContextVersion

    public Layout ServiceContextVersion { get; set; }

Configures "version" for the "serviceContext" when [SendJsonPayload](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_SendJsonPayload) = true

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

### SpanId

    public Layout SpanId { get; set; }

The span ID within the trace associated with the log entry.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

**Remarks** See <https://cloud.google.com/logging/docs/reference/v2/rpc/google.logging.v2#logentry>
for more information. Note that the Trace API v2 uses a 16-character hexadecimal
encoding of an 8-byte array, ex: `000000000000004a`

### TaskPendingLimit

    public int TaskPendingLimit { get; set; }

Configures how many outstanding write tasks before starting to throttle. Defaults to 5.

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

### TimeoutSeconds

    public int TimeoutSeconds { get; set; }

How many seconds to wait for task completion before starting new task

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

### TraceId

    public Layout TraceId { get; set; }

Trace ID of the trace associated to the Log Entry.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

**Remarks** See <https://cloud.google.com/logging/docs/reference/v2/rpc/google.logging.v2#logentry>
for more information. Note that this property, when rendered, should only return the
actual trace ID, not including the resource path, ex: '06796866738c859f2f19b7cfb3214824'.

### TraceSampled

    public Layout TraceSampled { get; set; }

The sampling decision of the trace associated with the log entry.
true means that the trace identified by [TraceId](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.NLog/latest/Google.Cloud.Logging.NLog.GoogleStackdriverTarget#Google_Cloud_Logging_NLog_GoogleStackdriverTarget_TraceId) was sampled for storage in a trace backend.
false means that the trace was not sampled for storage when this log entry was written,
or the sampling decision was unknown at the time.
A non-sampled trace value is still useful as a request correlation identifier. The default is false.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `NLog.Layouts.Layout` |   |

**Remarks** See <https://cloud.google.com/logging/docs/reference/v2/rpc/google.logging.v2#logentry>
for more information. Note that, when rendered, this may return "true" (case insentive) or 1 to
indicate a true value for [TraceSampled](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Logging.V2/latest/Google.Cloud.Logging.V2.LogEntry.html#Google_Cloud_Logging_V2_LogEntry_TraceSampled). Else, false will be set.

## Methods

### CloseTarget()

    protected override void CloseTarget()

Closes / Disposes the Target
**Overrides** NLog.Targets.Target.CloseTarget()

### FlushAsync(AsyncContinuation)

    protected override void FlushAsync(AsyncContinuation asyncContinuation)

Flush any pending log messages

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `asyncContinuation` | `NLog.Common.AsyncContinuation` The asynchronous continuation to be called on flush completed. |

**Overrides** NLog.Targets.Target.FlushAsync(NLog.Common.AsyncContinuation) **Remarks** The asynchronous continuation parameter must be called on flush completed

### InitializeTarget()

    protected override void InitializeTarget()

Initializes the target.
**Overrides** NLog.Targets.Target.InitializeTarget()

### Write(AsyncLogEventInfo)

    protected override void Write(AsyncLogEventInfo logEvent)

Writes async log event to the log target.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `logEvent` | `NLog.Common.AsyncLogEventInfo` Logging event to be written out. |

**Overrides** NLog.Targets.Target.Write(NLog.Common.AsyncLogEventInfo)

### Write(IList\<AsyncLogEventInfo\>)

    protected override void Write(IList<AsyncLogEventInfo> logEvents)

Writes a list of logging events to the log target.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `logEvents` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1NLog.Common.AsyncLogEventInfo` |

**Overrides** [Target.Write(IList\<AsyncLogEventInfo\>)](https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1)