Skip to content

Commit

Permalink
Move NLog configuration into docs directory and expand it
Browse files Browse the repository at this point in the history
  • Loading branch information
jskeet committed Dec 7, 2020
1 parent bb422c1 commit a0f7730
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
using Google.Cloud.ClientTesting;
using Google.Cloud.Logging.V2;
using NLog;
using NLog.Config;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Xml;
using Xunit;
Expand All @@ -36,6 +34,8 @@ public class GoogleStackdriverTargetSnippets

public GoogleStackdriverTargetSnippets(NLogSnippetFixture fixture) => _fixture = fixture;

// Resource: nlog-jsonTemplate.xml nlog_jsonTemplate

[Fact]
public void Overview()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
</extensions>

<targets async="true">
<target type="GoogleStackdriver" projectId="PROJECT_ID" logId="LOG_ID" name="stackdriver" resourceType="container" sendJsonPayload="true" enableJsonLayout="true" includeCallSite ="true" includeCallSiteStackTrace="true" IncludeEventProperties="false" IncludeMdlc="true">
<target type="GoogleStackdriver" name="stackdriver"
projectId="PROJECT_ID" logId="LOG_ID" resourceType="container"
includeCallSite ="true" includeCallSiteStackTrace="true" includeEventProperties="false" includeMdlc="true"
sendJsonPayload="true" enableJsonLayout="true">
<contextproperty name="contextProp" layout="propContextLayout" />
<layout xsi:type="JsonLayout" includeAllProperties="true">
<attribute name="someProp" layout="prop" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
</extensions>

<targets async="true">
<target name="stackdriver" xsi:type="GoogleStackdriver" projectId="PROJECT_ID" logId="LOG_ID" />
<target name="stackdriver" xsi:type="GoogleStackdriver" projectId="PROJECT_ID" logId="LOG_ID">
<!-- Potentially additional configuration -->
</target>
<target name="console" xsi:type="Console" />
</targets>

Expand Down
55 changes: 0 additions & 55 deletions apis/Google.Cloud.Logging.NLog/Google.Cloud.Logging.NLog/readme.md

This file was deleted.

24 changes: 24 additions & 0 deletions apis/Google.Cloud.Logging.NLog/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,27 @@ If executing on [Google App Engine (GAE)](https://cloud.google.com/appengine/),
[Google Kubernetes Engine (GKE)](https://cloud.google.com/kubernetes-engine/),
or [Google Compute Engine (GCE)](https://cloud.google.com/compute/),
then the `projectId="PROJECT_ID"` configuration setting can be omitted; it will be auto-detected from the platform at run-time.

## Configuration options

- `ProjectId` - Google Cloud project ID where logs will be sent to. Can be omitted if executing on on [Google App Engine (GAE)](https://cloud.google.com/appengine/) or [Google Compute Engine (GCE)](https://cloud.google.com/compute/)
- `LogId` - Name of log under the resource type (Default = "Default")
- `DisableResourceTypeDetection` - Defaults to false. Setting this to true disables automatic resource type detection based on platform detection.
- `ResourceType` - Resource type for logs. Must be one of the supported types listed in the [cloud logging documentation](https://cloud.google.com/logging/docs/api/v2/resource-list). This is not needed if resource type detection is successful. If resource type detection fails or is disabled, and this is not set, the resource type in log entries is set to "global".
- `ResourceLabel` - Used to specify extra labels as shown in the [Monitoring Resource Types](https://cloud.google.com/logging/docs/api/v2/resource-list) list.
- `ContextProperty` - Allows custom labels to be added to the log entries as extra metadata.
- `CredentialFile` - Credentials using a JSON file, instead of using the application default credentials
- `CredentialJson` - Credentials using raw JSON input, instead of using the application default credentials
- `IncludeCallSite` - Include `LogEntrySourceLocation` extracted from NLog callsite. (This only includes the function name.)
- `IncludeCallSiteStackTrace` - Include `LogEntrySourceLocation` extracted from NLog callsite. (This also includes file name and line number.)
- `IncludeEventProperties` - Includes structured logging properties from NLog `LogEventInfo.Properties`.
- `IncludeMdlc` - Include async thread context properties from NLog MappedDiagnosticsLogicalContext
- `SendJsonPayload` - Use the `jsonPayload` property in log entries instead of `textPayload`. When this is enabled, properties are set within the payload instead of as custom labels
- `ServiceContextName` - Configures the "service" in "serviceContext" when sending a JSON payload. (Defaults to the `AppDomain.FriendlyName` of the running code.)
- `ServiceContextVersion` - Configures the "version" in "serviceContext" when sending a JSON payload. (Defaults to the `FileVersion` of the entry assembly.)
- `EnableJsonLayout` - Uses NLog's native JSON layout to format JSON payloads, completely replacing the default layout.
- `JsonConverter` or `JsonConverterTypeName`/`JsonConverterMethodName` - Configures a custom conversion for individual values within a JSON payload.

Many of the options above are used to configure the JSON payload within the emitted log entries. The configuration file below uses a JSON layout via NLog configuration to completely replace the payload.

[!code-xml[](obj/snippets/Google.Cloud.Logging.NLog.GoogleStackdriverTarget.txt#nlog_jsonTemplate)]

0 comments on commit a0f7730

Please sign in to comment.