Skip to content

Commit d8868ee

Browse files
committed
update to version 3.6.0, cleanup docs and comments
1 parent 989b564 commit d8868ee

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Readme: https://github.com/manigandham/serilog-sinks-googlecloudlogging/blob/master/README.md
44

5+
## 3.6.0
6+
- Add `TraceSampled` to log correlation set of properties.
7+
- Update documentation.
8+
59
## 3.5.0
610
- Refactored sink to accept [`ITextFormatter`](https://github.com/serilog/serilog/wiki/Formatting-Output#custom-text-formatters) for full control over rendering a log event.
711
- Config validation on sink initialization will throw exceptions for known bad config values.

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Built for `netstandard2.0`, `net5.0`
66

77
Release notes here: [CHANGELOG.md](CHANGELOG.md)
88

9-
## Getting started
9+
## Usage
1010

1111
#### Install [package from Nuget](https://www.nuget.org/packages/Serilog.Sinks.GoogleCloudLogging/):
1212

@@ -23,9 +23,10 @@ Log.Logger = new LoggerConfiguration().WriteTo.GoogleCloudLogging(config).Create
2323

2424
#### Configure Logger (using config file):
2525

26-
This requires ['serilog-settings-configuration'](https://github.com/serilog/serilog-settings-configuration) to load sinks using an `appsettings.json` file.
26+
This requires the [`serilog-settings-configuration`](https://github.com/serilog/serilog-settings-configuration) package.
2727

2828
```json
29+
// appsettings.json or other config file
2930
"Serilog": {
3031
"Using": [ "Serilog.Sinks.GoogleCloudLogging" ],
3132
"MinimumLevel": "Information",
@@ -52,32 +53,33 @@ var config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional
5253
Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(config).CreateLogger();
5354
```
5455

55-
#### GCP authentication:
56+
## GCP Authentication:
5657

57-
This library uses the [`Google-Cloud-Dotnet`](https://googleapis.github.io/google-cloud-dotnet/) libraries which authenticate using the [Application Default Credentials](https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application) found on the host. This is automatic on GCE VMs or you can use the [`gcloud`](https://cloud.google.com/sdk/) SDK to authenticate manually. The service account must have the [`Logs Writer`](https://cloud.google.com/logging/docs/access-control) permission to send logs.
58+
This library uses the [Google Cloud .NET](https://cloud.google.com/dotnet/docs) client libraries which authenticate using the [Application Default Credentials](https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application) found on the host. This is automatic on Google Cloud (GCE, GKE, Cloud Run, AppEngine) or you can use the [gcloud SDK](https://cloud.google.com/sdk/) to authenticate manually.
59+
60+
The service account requires the [`Logs Writer`](https://cloud.google.com/logging/docs/access-control) permission to send logs.
5861

5962
## Sink Options
6063

6164
Name | Default | Description
6265
---- | ------- | -----------
6366
`ProjectId` | | Google Cloud project ID where logs will be sent. Will be automatically set to host project if running in GCP, otherwise required.
64-
`ResourceType` | `global` | Resource type for all log output. Will be automatically discovered if running in GCP, otherwise required. Must be one of the supported types listed in the [cloud logging documentation](https://cloud.google.com/logging/docs/api/v2/resource-list).
65-
`LogName` | `Default` | Name of the log. This is required if `UseSourceContextAsLogName` is false.
67+
`ResourceType` | `"global"` | Resource type for all log output. Will be automatically discovered if running in GCP, otherwise required. See [Monitored Resources and Services](https://cloud.google.com/logging/docs/api/v2/resource-list) for supported types.
68+
`LogName` | `"Default"` | Name of the log.
6669
`Labels` | | `Dictionary<string, string>` of properties added to all log entries.
6770
`ResourceLabels` | | `Dictionary<string, string>` of properties added to all log entries, at the resource level. See [Monitored Resources and Services](https://cloud.google.com/logging/docs/api/v2/resource-list) for recognized labels.
68-
`UseSourceContextAsLogName` | True | The log name for a log entry will be set to the [SourceContext](https://github.com/serilog/serilog/wiki/Writing-Log-Events#source-contexts) property if it's available.
69-
`UseJsonOutput` | False | Structured logs can be sent as text with labels or as a JSON object, see details below.
70-
`GoogleCredentialJson` | | GCP client libraries use [Application Default Credentials](https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application). If these are not available or you need to use other credentials, set the JSON text of a credential file directly.
71+
`UseSourceContextAsLogName` | True | The log name for a log entry will be set to the [SourceContext](https://github.com/serilog/serilog/wiki/Writing-Log-Events#source-contexts) property if available.
72+
`UseJsonOutput` | False | Serialize log entries as JSON for structured logging. See details below.
73+
`UseLogCorrelation` | False | Integrate logs with [Cloud Trace](https://cloud.google.com/trace) by setting `Trace`, `SpanId`, `TraceSampled` properties if available.
7174
`ServiceName` | | Name of the service added as metadata to log entries. Required to forward logged exceptions to Google Cloud Error Reporting. Must also set `UseJsonOutput` to true.
7275
`ServiceVersion` | | Version of the service added as metadata to log entries.
76+
`GoogleCredentialJson` | | GCP client libraries use [Application Default Credentials](https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application). If these are not available or you need to use other credentials, set the content of a JSON credential file directly.
7377

74-
#### Output Type
75-
76-
Serilog uses structured logging which means each log line is a formatting template with attached properties that are combined to create the final output. When `UseJsonOutput` is false, the output is sent as `TextPayload` to GCP with any properties serialized to string key/value labels.
78+
## Logging Output
7779

78-
If `UseJsonOutput` is set to true, the output will be sent as `JsonPayload` to maintain the original data types. This is helpful for querying child properties or numeric values in the Log Viewer, and will also capture property names even if they have null values.
80+
Serilog uses structured logging but logs are sent to GCP as a `TextPayload` with properties serialized to string labels by default. Enable `UseJsonOutput` to send logs as a `JsonPayload` with the proper data types. This provides richer logs with better querying support and will also capture property names even if they have null values.
7981

80-
WARNING: JSON output only accepts numeric values as `double` so all numbers will be converted. Large integers and floating-point values will lose precision. If you want the exact value preserved then log it as a string instead.
82+
*NOTE*: JSON output only accepts numeric values as `double` so all numbers will be converted. Large integers and floating-point values will lose precision. If you want the exact value preserved then log it as a string instead.
8183

8284
#### Log Level Mapping
8385

@@ -92,6 +94,6 @@ Warning | Warning
9294
Error | Error
9395
Fatal | Critical
9496

95-
## Viewing Logs
97+
#### Viewing Logs
9698

97-
Logs will appear in the Google Cloud Console Log Viewer: https://console.cloud.google.com/logs/viewer
99+
View and query logs in the Google Cloud Console Logs Explorer: https://console.cloud.google.com/logs/viewer

src/Serilog.Sinks.GoogleCloudLogging/GoogleCloudLoggingSinkOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public class GoogleCloudLoggingSinkOptions
3939
public bool UseSourceContextAsLogName { get; set; }
4040

4141
/// <summary>
42-
/// Serialize log entries as JSON object instead of strings to preserve structure and data types for rich querying.
42+
/// Serialize log entries as JSON objects instead of strings to preserve structure and data types for rich querying.
4343
/// Disabled by default. Must be enabled for logged exceptions to be forwarded to StackDriver Error Reporting.
4444
/// </summary>
4545
public bool UseJsonOutput { get; set; }
4646

4747
/// <summary>
48-
/// Integrate logs with Cloud Trace by setting LogEntry.Trace and LogEntry.SpanId if the LogEvent contains TraceId and SpanId properties.
48+
/// Integrate logs with Cloud Trace by setting `Trace`, `SpanId`, `TraceSampled` properties on the LogEvent.
4949
/// Required for Google Cloud Trace Log Correlation.
5050
/// See https://cloud.google.com/trace/docs/trace-log-integration
5151
/// </summary>

src/Serilog.Sinks.GoogleCloudLogging/LogFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void WritePropertyAsLabel(LogEntry log, string propKey, LogEventPropertyV
119119
break;
120120

121121
case SequenceValue sequenceValue:
122-
log.Labels.Add(propKey, string.Join(",", sequenceValue.Elements));
122+
log.Labels.Add(propKey, String.Join(",", sequenceValue.Elements));
123123
break;
124124

125125
case StructureValue structureValue when structureValue.Properties.Count > 0:

src/Serilog.Sinks.GoogleCloudLogging/Serilog.Sinks.GoogleCloudLogging.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<PackageVersion>3.5.0</PackageVersion>
4+
<PackageVersion>3.6.0</PackageVersion>
55
<Description>Serilog sink that writes events to Google Cloud Platform (Stackdriver) Logging.</Description>
66
<Authors>Mani Gandham</Authors>
77
<PackageLicenseExpression>MIT</PackageLicenseExpression>

0 commit comments

Comments
 (0)