Serilog.Sinks.GoogleCloudLogging
2.1.1
See the version list below for details.
dotnet add package Serilog.Sinks.GoogleCloudLogging --version 2.1.1
NuGet\Install-Package Serilog.Sinks.GoogleCloudLogging -Version 2.1.1
<PackageReference Include="Serilog.Sinks.GoogleCloudLogging" Version="2.1.1" />
paket add Serilog.Sinks.GoogleCloudLogging --version 2.1.1
#r "nuget: Serilog.Sinks.GoogleCloudLogging, 2.1.1"
// Install Serilog.Sinks.GoogleCloudLogging as a Cake Addin #addin nuget:?package=Serilog.Sinks.GoogleCloudLogging&version=2.1.1 // Install Serilog.Sinks.GoogleCloudLogging as a Cake Tool #tool nuget:?package=Serilog.Sinks.GoogleCloudLogging&version=2.1.1
Serilog.Sinks.GoogleCloudLogging
Serilog sink that writes events to Google Cloud Platform Stackdriver Logging. View release notes here: CHANGELOG.md
Getting started
Install package from Nuget:
dotnet add package Serilog.Sinks.GoogleCloudLogging
Configure Logger (using code):
var config = new GoogleCloudLoggingSinkOptions { ProjectId = "YOUR_PROJECT_ID", UseJsonOutput = true };
Log.Logger = new LoggerConfiguration().WriteTo.GoogleCloudLogging(config).CreateLogger();
Configure Logger (using config file):
This requires 'serilog-settings-configuration' to load sinks using an appsettings.json
file.
"Serilog": {
"Using": [ "Serilog.Sinks.GoogleCloudLogging" ],
"MinimumLevel": "Warning",
"WriteTo": [
{
"Name": "GoogleCloudLogging",
"Args": {
"projectID": "YOUR_PROJECT_ID",
"useJsonOutput": "true",
"resourceType": "k8s_cluster",
"resourceLabels": {
"project_id": "PROJECT-ID-HERE-12345",
"location": "LOCATION-STRING-HERE-region-name",
"cluster_name": "CLUSTER-NAME-HERE-container-cluster"
}
}
}
]
}
var config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(config).CreateLogger();
GCP authentication:
This library uses the Google-Cloud-Dotnet
libraries which authenticate using the Application Default Credentials found on the host. This is automatic on GCE VMs or you can use the gcloud
SDK to authenticate manually. The service account must have the Logs Writer
permission to send logs.
Sink Options
Name | Default | Description |
---|---|---|
ProjectId |
Google Cloud project ID where logs will be sent. Will be automatically set to host project if running in GCP, otherwise required. | |
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. |
LogName |
Default |
Name of the log. This is required if UseSourceContextAsLogName is false. |
Labels |
Dictionary<string, string> of properties added to all log entries. |
|
ResourceLabels |
Dictionary<string, string> of properties added to all log entries, at the resource level. See Monitored Resources and Services for recognized labels. |
|
UseSourceContextAsLogName |
True | The log name for a log entry will be set to the SourceContext property if it's available. |
UseJsonOutput |
False | Structured logs can be sent as text with labels or as a JSON object, see details below. |
GoogleCredentialJson |
GCP client libraries use Application Default Credentials. If these are not available or you need to use other credentials, set the JSON text of a credential file directly. | |
ServiceName |
Name of the service added as metadata to log entries. Required to forward logged exceptions to StackDriver Error Reporting. Must also set UseJsonOutput to true. |
|
ServiceVersion |
Version of the service added as metadata to log entries. Defaults to <unknown> . |
Output Type
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.
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.
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.
Viewing Logs
Logs will appear in the Google Cloud Console Log Viewer: https://console.cloud.google.com/logs/viewer
When using default options, logs will appear under these filter settings:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.5 is compatible. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.5
- Google.Cloud.Logging.V2 (>= 2.2.0)
- NETStandard.Library (>= 1.6.1)
- Serilog (>= 2.8.0)
- Serilog.Sinks.PeriodicBatching (>= 2.2.0)
-
.NETStandard 2.0
- Google.Cloud.Logging.V2 (>= 2.2.0)
- Serilog (>= 2.8.0)
- Serilog.Sinks.PeriodicBatching (>= 2.2.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Serilog.Sinks.GoogleCloudLogging:
Package | Downloads |
---|---|
PegasusLoggingService
Package Description |
|
Pegasus_Logging
Package Description |
|
Findep.AspNetCore.Microservices
Core Library for FINDEP Microservices based on ASP.NET Core |
|
Neocortex.Extension
Neocortex.Extension es una biblioteca de extensiones para .NET Core que proporciona integraciones fáciles para logging con Google y caching. Mejora el rendimiento de tus aplicaciones con un sistema de caché eficiente y una integración directa con los servicios de logging de Google. Características: Logging con Google: Registra eventos directamente en Google para monitoreo. Caché eficiente: Optimiza el rendimiento con almacenamiento en caché. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.0 | 2,213,750 | 6/14/2022 |
4.0.0 | 229,615 | 4/5/2022 |
3.7.0 | 144,862 | 2/20/2022 |
3.6.0 | 285,847 | 8/30/2021 |
3.5.0 | 49,831 | 6/10/2021 |
3.4.0 | 27,505 | 4/25/2021 |
3.3.3 | 66,932 | 3/15/2021 |
3.3.0 | 91,342 | 9/21/2020 |
3.2.0 | 86,068 | 6/18/2020 |
3.0.0 | 70,215 | 3/20/2020 |
2.4.1 | 2,620 | 3/18/2020 |
2.4.0 | 28,869 | 2/5/2020 |
2.3.0 | 2,060 | 1/15/2020 |
2.2.1 | 1,832 | 1/12/2020 |
2.2.0 | 28,085 | 10/8/2019 |
2.1.1 | 3,240 | 10/6/2019 |
2.1.0 | 28,562 | 9/17/2019 |
2.0.0 | 163,916 | 5/24/2019 |
1.10.0 | 49,272 | 4/4/2019 |
1.9.0 | 699 | 4/4/2019 |
1.7.0 | 95,695 | 2/8/2019 |
1.6.0 | 6,156 | 2/7/2019 |
1.5.0 | 41,763 | 10/5/2018 |
1.4.7 | 7,143 | 9/10/2018 |
1.4.6 | 14,326 | 6/2/2018 |
1.4.5 | 2,093 | 5/19/2018 |
1.4.0 | 1,058 | 5/19/2018 |
1.3.1 | 3,113 | 12/16/2017 |
1.3.0 | 1,440 | 12/8/2017 |
1.2.0 | 1,171 | 11/30/2017 |
1.1.0 | 1,325 | 11/28/2017 |
1.0.0 | 1,823 | 9/6/2017 |