Class GoogleStackdriverTarget (4.0.0)

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

Appends logging events to Google Stackdriver Logging.

Inheritance

Object > NLog.Targets.Target > NLog.Targets.TargetWithLayout > NLog.Targets.TargetWithContext > GoogleStackdriverTarget

Implements

IDisposable

Namespace

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; }
Property Value
TypeDescription
IList<NLog.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 is set.

Property Value
TypeDescription
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 is set.

Property Value
TypeDescription
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
TypeDescription
Boolean

EnableJsonLayout

public bool EnableJsonLayout { get; set; }

Fills JsonPayload in specified by user way with NLog.Layouts.JsonLayout layout type. JSON values serialization can be customized using JsonConverterTypeName and JsonConverterMethodName, or JsonConverter.

Property Value
TypeDescription
Boolean

JsonConverter

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

When SendJsonPayload is true, a custom JSON serialization method may be programatically specified here. Must not be set if JsonConverterTypeName and JsonConverterMethodName are set.

Property Value
TypeDescription
Func<Object, Value>

JsonConverterMethodName

public string JsonConverterMethodName { get; set; }

When SendJsonPayload is true, a custom JSON serialization method may be specified by type-name and method-name. Specify the type-name in 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 is set.

Property Value
TypeDescription
String

JsonConverterTypeName

public string JsonConverterTypeName { get; set; }

When 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. The instance or static method must have the signature Value MyMethod(object obj) or JToken MyMethod(object o). Must not be set if JsonConverter is set.

Property Value
TypeDescription
String

LogId

public Layout LogId { get; set; }

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

Property Value
TypeDescription
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
TypeDescription
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
TypeDescription
IList<NLog.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
TypeDescription
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 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 instead of TextPayload. JSON values serialization can be customized using JsonConverterTypeName and JsonConverterMethodName, or JsonConverter.

Property Value
TypeDescription
Boolean

ServiceContextName

public Layout ServiceContextName { get; set; }

Configures "service" for the "serviceContext" when SendJsonPayload = true

Property Value
TypeDescription
NLog.Layouts.Layout

ServiceContextVersion

public Layout ServiceContextVersion { get; set; }

Configures "version" for the "serviceContext" when SendJsonPayload = true

Property Value
TypeDescription
NLog.Layouts.Layout

SpanId

public Layout SpanId { get; set; }

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

Property Value
TypeDescription
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
TypeDescription
Int32

TimeoutSeconds

public int TimeoutSeconds { get; set; }

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

Property Value
TypeDescription
Int32

TraceId

public Layout TraceId { get; set; }

Trace ID of the trace associated to the Log Entry.

Property Value
TypeDescription
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 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
TypeDescription
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. Else, false will be set.

Methods

CloseTarget()

protected override void CloseTarget()

Closes / Disposes the Target

Overrides
NLog.Targets.TargetWithContext.CloseTarget()

FlushAsync(AsyncContinuation)

protected override void FlushAsync(AsyncContinuation asyncContinuation)
Parameter
NameDescription
asyncContinuationNLog.Common.AsyncContinuation
Overrides
NLog.Targets.Target.FlushAsync(NLog.Common.AsyncContinuation)

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
NameDescription
logEventNLog.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
NameDescription
logEventsIList<NLog.Common.AsyncLogEventInfo>
Overrides
NLog.Targets.Target.Write(System.Collections.Generic.IList<NLog.Common.AsyncLogEventInfo>)