[Target("GoogleStackdriver")]
public class GoogleStackdriverTarget : TargetWithContext, ISupportsInitialize, IDisposable, IIncludeContext
Appends logging events to Google Stackdriver Logging.
Inheritance
Object > NLog.Targets.Target > NLog.Targets.TargetWithLayout > NLog.Targets.TargetWithContext > GoogleStackdriverTargetImplements
IDisposableNamespace
Google.Cloud.Logging.NLogAssembly
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 | |
---|---|
Type | Description |
IList<NLog.Targets.TargetPropertyWithContext> |
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 | |
---|---|
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 is set.
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 |
Boolean |
EnableJsonLayout
public bool EnableJsonLayout { get; set; }
Fills 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 and JsonConverterMethodName, or JsonConverter.
Property Value | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
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 |
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 | |
---|---|
Type | Description |
String |
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.
true
, then this platform detection
is not performed, and this ResourceType defaults to "global" if not set.
SendJsonPayload
public bool SendJsonPayload { get; set; }
Fills Google.Cloud.Logging.V2.LogEntry.JsonPayload instead of Google.Cloud.Logging.V2.LogEntry.TextPayload. JSON values serialization can be customized using JsonConverterTypeName and JsonConverterMethodName, or JsonConverter.
Property Value | |
---|---|
Type | Description |
Boolean |
ServiceContextName
public Layout ServiceContextName { get; set; }
Configures "service" for the "serviceContext" when SendJsonPayload = true
Property Value | |
---|---|
Type | Description |
NLog.Layouts.Layout |
ServiceContextVersion
public Layout ServiceContextVersion { get; set; }
Configures "version" for the "serviceContext" when 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 |
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 |
Int32 |
TimeoutSeconds
public int TimeoutSeconds { get; set; }
How many seconds to wait for task completion before starting new task
Property Value | |
---|---|
Type | Description |
Int32 |
TraceId
public Layout TraceId { get; set; }
Trace ID of the trace associated to the Log Entry.
Property Value | |
---|---|
Type | Description |
NLog.Layouts.Layout |
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 | |
---|---|
Type | Description |
NLog.Layouts.Layout |
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 Google.Cloud.Logging.V2.LogEntry.TraceSampled. Else, false will be set.
Methods
CloseTarget()
protected override void CloseTarget()
Closes / Disposes the Target
FlushAsync(AsyncContinuation)
protected override void FlushAsync(AsyncContinuation asyncContinuation)
Parameter | |
---|---|
Name | Description |
asyncContinuation | NLog.Common.AsyncContinuation |
InitializeTarget()
protected override void InitializeTarget()
Initializes the target.
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. |
Write(IList<AsyncLogEventInfo>)
protected override void Write(IList<AsyncLogEventInfo> logEvents)
Writes a list of logging events to the log target.
Parameter | |
---|---|
Name | Description |
logEvents | IList<NLog.Common.AsyncLogEventInfo> |