-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
2,110 additions
and
2,110 deletions.
There are no files selected for viewing
1,170 changes: 585 additions & 585 deletions
1,170
apis/Google.Cloud.Logging.Log4Net/Google.Cloud.Logging.Log4Net/GoogleStackdriverAppender.cs
Large diffs are not rendered by default.
Oops, something went wrong.
1,364 changes: 682 additions & 682 deletions
1,364
.../Google.Cloud.Logging.NLog/Google.Cloud.Logging.NLog.Tests/GoogleStackdriverTargetTest.cs
Large diffs are not rendered by default.
Oops, something went wrong.
240 changes: 120 additions & 120 deletions
240
apis/Google.Cloud.Logging.NLog/Google.Cloud.Logging.NLog.sln
Large diffs are not rendered by default.
Oops, something went wrong.
1,206 changes: 603 additions & 603 deletions
1,206
apis/Google.Cloud.Logging.NLog/Google.Cloud.Logging.NLog/GoogleStackdriverTarget.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 56 additions & 56 deletions
112
apis/Google.Cloud.Logging.NLog/Google.Cloud.Logging.NLog/ToStringJsonConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Google.Cloud.Logging.NLog | ||
{ | ||
/// <summary> | ||
/// JSON converter that just calls ToString on the target value (when non-null). | ||
/// This is configured as the converter for types that will otherwise spew a lot of irrelevant JSON | ||
/// into logs. | ||
/// </summary> | ||
internal sealed class ToStringJsonConverter : JsonConverter | ||
{ | ||
private readonly System.Type _type; | ||
|
||
/// <inheritdoc /> | ||
public override bool CanRead => false; | ||
|
||
public ToStringJsonConverter(System.Type type) => | ||
_type = type; | ||
|
||
/// <inheritdoc /> | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
if (value is null) | ||
{ | ||
writer.WriteNull(); | ||
} | ||
else | ||
{ | ||
writer.WriteValue(value.ToString()); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer) => | ||
throw new NotSupportedException("Only serialization is supported"); | ||
|
||
/// <inheritdoc /> | ||
public override bool CanConvert(System.Type objectType) => | ||
_type.IsAssignableFrom(objectType); | ||
} | ||
} | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Google.Cloud.Logging.NLog | ||
{ | ||
/// <summary> | ||
/// JSON converter that just calls ToString on the target value (when non-null). | ||
/// This is configured as the converter for types that will otherwise spew a lot of irrelevant JSON | ||
/// into logs. | ||
/// </summary> | ||
internal sealed class ToStringJsonConverter : JsonConverter | ||
{ | ||
private readonly System.Type _type; | ||
|
||
/// <inheritdoc /> | ||
public override bool CanRead => false; | ||
|
||
public ToStringJsonConverter(System.Type type) => | ||
_type = type; | ||
|
||
/// <inheritdoc /> | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
if (value is null) | ||
{ | ||
writer.WriteNull(); | ||
} | ||
else | ||
{ | ||
writer.WriteValue(value.ToString()); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer) => | ||
throw new NotSupportedException("Only serialization is supported"); | ||
|
||
/// <inheritdoc /> | ||
public override bool CanConvert(System.Type objectType) => | ||
_type.IsAssignableFrom(objectType); | ||
} | ||
} |
110 changes: 55 additions & 55 deletions
110
apis/Google.Cloud.Logging.NLog/Google.Cloud.Logging.NLog/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
# Google Cloud Logging NLog target | ||
|
||
`Google.Cloud.Logging.NLog` is a .NET client library to integrate [Google Stackdriver Logging](https://cloud.google.com/logging/) | ||
with [NLog](https://github.com/NLog/NLog). | ||
|
||
## Installation | ||
|
||
Install the `Google.Cloud.Logging.NLog` package from NuGet. Add it to | ||
your project in the normal way (for example by right-clicking on the | ||
project in Visual Studio and choosing "Manage NuGet Packages..."). | ||
Please ensure you enable pre-release packages (for example, in the | ||
Visual Studio NuGet user interface, check the "Include prerelease" | ||
box). | ||
|
||
## Getting started | ||
|
||
This library uses the [Google-Cloud-Dotnet](https://googleapis.github.io/google-cloud-dotnet/) libraries which authenticate | ||
using the default service account on the machine. This is automatic on GCE VMs or you can use the [gcloud](https://cloud.google.com/sdk/) SDK | ||
to authenticate yourself. The service account must have the [Logs Writer](https://cloud.google.com/logging/docs/access-control) permission to send logs. | ||
|
||
When using default options, logs will appear under these filter settings in the GCP Console. | ||
|
||
## Target 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/) | ||
* **ResourceType** - Resource type for logs (Default = "global"). Must be one of the supported types listed in the [cloud logging documentation](https://cloud.google.com/logging/docs/api/v2/resource-list). | ||
* **LogId** - Name of log under the resource type (Default = "Default") | ||
* **DisableResourceTypeDetection** - Defaults to false. Setting this to true disables automatic resourceType setting based on platform detection. | ||
* **ResourceLabel** - If resourceType has been manually set, then resourceLabel is 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 default credentials (GOOGLE_APPLICATION_CREDENTIALS) | ||
* **CredentialJson** - Credentials using raw JSON input, instead of using the default credentials (GOOGLE_APPLICATION_CREDENTIALS) | ||
* **IncludeCallSite** - Include LogEntrySourceLocation extracted from NLog callsite (Only include function name) | ||
* **IncludeCallSiteStackTrace** - Include LogEntrySourceLocation extracted from NLog callsite (Also include filename and linenumber) | ||
* **IncludeEventProperties** - Includes structured logging properties from NLog LogEventInfo.Properties | ||
* **IncludeMdlc** - Include async thread context properties from NLog MappedDiagnosticsLogicalContext | ||
* **SendJsonPayload** - Instead of sending properties as custom labels, then they are sent as Json-Properties in JsonPayload (without TextPayload) | ||
* **ServiceContextName** - Configures the "service" in "serviceContext" when SendJsonPayload = true (Default = AppDomain FriendlyName) | ||
* **ServiceContextVersion** - Configures the "version" in "serviceContext" when SendJsonPayload = true (Default = Entry Assembly FileVersion) | ||
|
||
```xml | ||
<extensions> | ||
<add assembly="Google.Cloud.Logging.NLog" /> | ||
</extensions> | ||
<targets> | ||
<target type="GoogleStackdriver" | ||
name="String" | ||
projectId="your project ID" | ||
logId="your log ID" | ||
layout="Layout"> | ||
<resourcelabel name="String" layout="Layout" /><!-- repeated --> | ||
<contextproperty name="String" layout="Layout" /><!-- repeated --> | ||
</target> | ||
</targets> | ||
``` | ||
# Google Cloud Logging NLog target | ||
|
||
`Google.Cloud.Logging.NLog` is a .NET client library to integrate [Google Stackdriver Logging](https://cloud.google.com/logging/) | ||
with [NLog](https://github.com/NLog/NLog). | ||
|
||
## Installation | ||
|
||
Install the `Google.Cloud.Logging.NLog` package from NuGet. Add it to | ||
your project in the normal way (for example by right-clicking on the | ||
project in Visual Studio and choosing "Manage NuGet Packages..."). | ||
Please ensure you enable pre-release packages (for example, in the | ||
Visual Studio NuGet user interface, check the "Include prerelease" | ||
box). | ||
|
||
## Getting started | ||
|
||
This library uses the [Google-Cloud-Dotnet](https://googleapis.github.io/google-cloud-dotnet/) libraries which authenticate | ||
using the default service account on the machine. This is automatic on GCE VMs or you can use the [gcloud](https://cloud.google.com/sdk/) SDK | ||
to authenticate yourself. The service account must have the [Logs Writer](https://cloud.google.com/logging/docs/access-control) permission to send logs. | ||
|
||
When using default options, logs will appear under these filter settings in the GCP Console. | ||
|
||
## Target 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/) | ||
* **ResourceType** - Resource type for logs (Default = "global"). Must be one of the supported types listed in the [cloud logging documentation](https://cloud.google.com/logging/docs/api/v2/resource-list). | ||
* **LogId** - Name of log under the resource type (Default = "Default") | ||
* **DisableResourceTypeDetection** - Defaults to false. Setting this to true disables automatic resourceType setting based on platform detection. | ||
* **ResourceLabel** - If resourceType has been manually set, then resourceLabel is 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 default credentials (GOOGLE_APPLICATION_CREDENTIALS) | ||
* **CredentialJson** - Credentials using raw JSON input, instead of using the default credentials (GOOGLE_APPLICATION_CREDENTIALS) | ||
* **IncludeCallSite** - Include LogEntrySourceLocation extracted from NLog callsite (Only include function name) | ||
* **IncludeCallSiteStackTrace** - Include LogEntrySourceLocation extracted from NLog callsite (Also include filename and linenumber) | ||
* **IncludeEventProperties** - Includes structured logging properties from NLog LogEventInfo.Properties | ||
* **IncludeMdlc** - Include async thread context properties from NLog MappedDiagnosticsLogicalContext | ||
* **SendJsonPayload** - Instead of sending properties as custom labels, then they are sent as Json-Properties in JsonPayload (without TextPayload) | ||
* **ServiceContextName** - Configures the "service" in "serviceContext" when SendJsonPayload = true (Default = AppDomain FriendlyName) | ||
* **ServiceContextVersion** - Configures the "version" in "serviceContext" when SendJsonPayload = true (Default = Entry Assembly FileVersion) | ||
|
||
```xml | ||
<extensions> | ||
<add assembly="Google.Cloud.Logging.NLog" /> | ||
</extensions> | ||
<targets> | ||
<target type="GoogleStackdriver" | ||
name="String" | ||
projectId="your project ID" | ||
logId="your log ID" | ||
layout="Layout"> | ||
<resourcelabel name="String" layout="Layout" /><!-- repeated --> | ||
<contextproperty name="String" layout="Layout" /><!-- repeated --> | ||
</target> | ||
</targets> | ||
``` |