Serilog.Sinks.GoogleCloudLogging
3.7.0
See the version list below for details.
dotnet add package Serilog.Sinks.GoogleCloudLogging --version 3.7.0
NuGet\Install-Package Serilog.Sinks.GoogleCloudLogging -Version 3.7.0
<PackageReference Include="Serilog.Sinks.GoogleCloudLogging" Version="3.7.0" />
paket add Serilog.Sinks.GoogleCloudLogging --version 3.7.0
#r "nuget: Serilog.Sinks.GoogleCloudLogging, 3.7.0"
// Install Serilog.Sinks.GoogleCloudLogging as a Cake Addin #addin nuget:?package=Serilog.Sinks.GoogleCloudLogging&version=3.7.0 // Install Serilog.Sinks.GoogleCloudLogging as a Cake Tool #tool nuget:?package=Serilog.Sinks.GoogleCloudLogging&version=3.7.0
Serilog.Sinks.GoogleCloudLogging
Serilog sink that writes events to Google Cloud Logging.
Built for net6.0
, net5.0
, netstandard2.0
Release notes here: CHANGELOG.md
Usage
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 the serilog-settings-configuration
package.
// appsettings.json or other config file
"Serilog": {
"Using": [ "Serilog.Sinks.GoogleCloudLogging" ],
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "GoogleCloudLogging",
"Args": {
"projectID": "PROJECT-ID-12345",
"labels": {
"foo": "bar"
},
"useSourceContextAsLogName": true,
"useJsonOutput": true,
"restrictedToMinimumLevel": "Information"
}
}
]
}
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 .NET client and Application Default Credentials. The Logs Writer
permission is required to send logs.
- Run in GCE, GKE, Cloud Run, AppEngine to automatically have the Application Default Credentials set to the active service account.
- Or authenticate manually with the gcloud SDK on a server to set the Application Default Credentials.
- Or set the
GoogleCredentialJson
config option to a specific service account.
Sink Options
Option | Description |
---|---|
ProjectId | ID (not name) of GCP project where logs will be sent. Optional if running in GCP. Required if running elsewhere or to override the destination. |
ResourceType | Resource type for logs. Optional, automatically identified if running in GCP or will be set to "global". See Monitored Resources and Services for supported types. |
LogName | Name of the log. Optional, set to "Default". |
Labels | Optional Dictionary<string, string> labels added to all log entries. |
ResourceLabels | Optional Dictionary<string, string> labels added to all log entries, for the resource type. See Monitored Resources and Services for recognized labels. |
ServiceName | Name of the service added as metadata to log entries. |
ServiceVersion | Version of the service added as metadata to log entries. |
UseSourceContextAsLogName | The log name for a log entry will be set to the SourceContext property if available. |
UseJsonOutput | Serialize log entries as JSON for structured logging, see details below. Default is false . |
UseLogCorrelation | Integrate logs with Cloud Trace by setting Trace , SpanId , TraceSampled properties if available. Default is false . |
GoogleCredentialJson | Override Application Default Credentials with the content of a JSON credential file. |
Log Output
- Serilog uses structured logging but logs are sent to GCP as a
TextPayload
. EnableUseJsonOutput
to send logs as aJsonPayload
with rich data types for better querying support and will also capture property names even if they have null values. - 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.
Log Level Mapping
This table shows the mapping from Serilog LogLevel
to Google Cloud Logging LogSeverity
Serilog | Cloud Logging |
---|---|
Verbose | Debug |
Debug | Debug |
Information | Info |
Warning | Warning |
Error | Error |
Fatal | Critical |
Viewing Logs
View and query logs in the Google Cloud Console Logs Explorer: https://console.cloud.google.com/logs/viewer
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | 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 | 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 2.0
- Google.Cloud.Logging.V2 (>= 3.4.0)
- Serilog (>= 2.10.0)
- Serilog.Sinks.PeriodicBatching (>= 2.3.1)
- System.Text.Encodings.Web (>= 6.0.0)
-
net5.0
- Google.Cloud.Logging.V2 (>= 3.4.0)
- Serilog (>= 2.10.0)
- Serilog.Sinks.PeriodicBatching (>= 2.3.1)
- System.Text.Encodings.Web (>= 6.0.0)
-
net6.0
- Google.Cloud.Logging.V2 (>= 3.4.0)
- Serilog (>= 2.10.0)
- Serilog.Sinks.PeriodicBatching (>= 2.3.1)
- System.Text.Encodings.Web (>= 6.0.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,463,849 | 6/14/2022 |
4.0.0 | 236,474 | 4/5/2022 |
3.7.0 | 146,910 | 2/20/2022 |
3.6.0 | 289,146 | 8/30/2021 |
3.5.0 | 50,025 | 6/10/2021 |
3.4.0 | 27,582 | 4/25/2021 |
3.3.3 | 67,972 | 3/15/2021 |
3.3.0 | 91,585 | 9/21/2020 |
3.2.0 | 86,353 | 6/18/2020 |
3.0.0 | 70,861 | 3/20/2020 |
2.4.1 | 2,656 | 3/18/2020 |
2.4.0 | 28,921 | 2/5/2020 |
2.3.0 | 2,071 | 1/15/2020 |
2.2.1 | 1,845 | 1/12/2020 |
2.2.0 | 28,171 | 10/8/2019 |
2.1.1 | 3,253 | 10/6/2019 |
2.1.0 | 28,574 | 9/17/2019 |
2.0.0 | 164,048 | 5/24/2019 |
1.10.0 | 49,330 | 4/4/2019 |
1.9.0 | 710 | 4/4/2019 |
1.7.0 | 95,775 | 2/8/2019 |
1.6.0 | 6,167 | 2/7/2019 |
1.5.0 | 41,780 | 10/5/2018 |
1.4.7 | 7,160 | 9/10/2018 |
1.4.6 | 14,386 | 6/2/2018 |
1.4.5 | 2,108 | 5/19/2018 |
1.4.0 | 1,073 | 5/19/2018 |
1.3.1 | 3,128 | 12/16/2017 |
1.3.0 | 1,455 | 12/8/2017 |
1.2.0 | 1,186 | 11/30/2017 |
1.1.0 | 1,341 | 11/28/2017 |
1.0.0 | 1,884 | 9/6/2017 |