You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add `TraceSampled` to log correlation set of properties.
7
+
- Update documentation.
8
+
5
9
## 3.5.0
6
10
- Refactored sink to accept [`ITextFormatter`](https://github.com/serilog/serilog/wiki/Formatting-Output#custom-text-formatters) for full control over rendering a log event.
7
11
- Config validation on sink initialization will throw exceptions for known bad config values.
Copy file name to clipboardExpand all lines: README.md
+18-16Lines changed: 18 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Built for `netstandard2.0`, `net5.0`
6
6
7
7
Release notes here: [CHANGELOG.md](CHANGELOG.md)
8
8
9
-
## Getting started
9
+
## Usage
10
10
11
11
#### Install [package from Nuget](https://www.nuget.org/packages/Serilog.Sinks.GoogleCloudLogging/):
12
12
@@ -23,9 +23,10 @@ Log.Logger = new LoggerConfiguration().WriteTo.GoogleCloudLogging(config).Create
23
23
24
24
#### Configure Logger (using config file):
25
25
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.
27
27
28
28
```json
29
+
// appsettings.json or other config file
29
30
"Serilog": {
30
31
"Using": [ "Serilog.Sinks.GoogleCloudLogging" ],
31
32
"MinimumLevel": "Information",
@@ -52,32 +53,33 @@ var config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional
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.
58
61
59
62
## Sink Options
60
63
61
64
Name | Default | Description
62
65
---- | ------- | -----------
63
66
`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.
66
69
`Labels` | | `Dictionary<string, string>` of properties added to all log entries.
67
70
`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.
71
74
`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.
72
75
`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.
73
77
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
77
79
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.
79
81
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.
81
83
82
84
#### Log Level Mapping
83
85
@@ -92,6 +94,6 @@ Warning | Warning
92
94
Error | Error
93
95
Fatal | Critical
94
96
95
-
## Viewing Logs
97
+
####Viewing Logs
96
98
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
0 commit comments