Serilog.Sinks.GoogleCloudLogging
5.0.0
dotnet add package Serilog.Sinks.GoogleCloudLogging --version 5.0.0
NuGet\Install-Package Serilog.Sinks.GoogleCloudLogging -Version 5.0.0
<PackageReference Include="Serilog.Sinks.GoogleCloudLogging" Version="5.0.0" />
paket add Serilog.Sinks.GoogleCloudLogging --version 5.0.0
#r "nuget: Serilog.Sinks.GoogleCloudLogging, 5.0.0"
// Install Serilog.Sinks.GoogleCloudLogging as a Cake Addin
#addin nuget:?package=Serilog.Sinks.GoogleCloudLogging&version=5.0.0
// Install Serilog.Sinks.GoogleCloudLogging as a Cake Tool
#tool nuget:?package=Serilog.Sinks.GoogleCloudLogging&version=5.0.0
Serilog.Sinks.GoogleCloudLogging
Serilog sink that writes events to Google Cloud Logging.
- Built for
net6.0
,net5.0
,netstandard2.0
- Release Notes
Usage
Install package from Nuget:
dotnet add package Serilog.Sinks.GoogleCloudLogging
Configure in code:
var config = new GoogleCloudLoggingSinkOptions { ProjectId = "YOUR_PROJECT_ID" };
Log.Logger = new LoggerConfiguration().WriteTo.GoogleCloudLogging(config).CreateLogger();
Or configure with config file:
This requires the serilog-settings-configuration
package.
"Serilog": {
"Using": [ "Serilog.Sinks.GoogleCloudLogging" ],
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "GoogleCloudLogging",
"Args": {
"projectID": "PROJECT-ID-12345",
"restrictedToMinimumLevel": "Information",
"labels": {
"foo": "bar"
}
}
}
]
}
var config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(config).CreateLogger();
- Serilog example for .NET 6: https://blog.datalust.co/using-serilog-in-net-6/
GCP Integration
Authentication
This library uses the Google Cloud .NET client and Application Default Credentials. The Logs Writer
permission is required to send logs. There are several different ways to set credentials:
- GCE, GKE, Cloud Run, AppEngine and other managed services will have the Application Default Credentials set to the active service account for the resource and can be used without any additional configuration.
- Authenticate manually with the gcloud SDK on a server to set the Application Default Credentials.
- Set the
GOOGLE_APPLICATION_CREDENTIALS
environment variable to specify the path to your JSON credentials file. - Set the
GoogleCredentialJson
config option to pass in the contents of your JSON credentials file.
Log Output
- Serilog is designed for structured logging which is fully supported by Google Cloud. Logs are sent as a JSON object (
JsonPayload
in the protobuf API) with labels, properties, metadata and any other data like stack traces automatically attached. - Numeric values in labels and properties will be converted to
double
during serialization because that is the only numeric type supported by JSON. Large integers and floating-point values will lose precision. If you want the exact value preserved then log it as a string instead. - View logs in the GCP Logs Explorer: https://console.cloud.google.com/logs/viewer
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. Automatically identified if running in GCP or will default to "global". See Monitored Resources and Services for supported types. |
LogName | Name of the log. Default is "Default", or will use SourceContext is setting is enabled. |
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. Required for logged exceptions to be forwarded to StackDriver Error Reporting. |
ServiceVersion | Version of the service added as metadata to log entries. Required for logged exceptions to be forwarded to StackDriver Error Reporting. |
UseSourceContextAsLogName | The log name for a log entry will be set to the SourceContext property if available. Default is true . |
UseLogCorrelation | Integrate logs with Cloud Trace by setting Trace , SpanId , TraceSampled properties if available. Default is true . |
GoogleCredentialJson | Override Application Default Credentials with the content of a JSON credential file. |
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 |
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.1 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETStandard 2.1
- Google.Cloud.Logging.V2 (>= 4.0.0)
- Serilog (>= 2.11.0)
- Serilog.Sinks.PeriodicBatching (>= 2.3.1)
- System.Text.Encodings.Web (>= 6.0.0)
-
net5.0
- Google.Cloud.Logging.V2 (>= 4.0.0)
- Serilog (>= 2.11.0)
- Serilog.Sinks.PeriodicBatching (>= 2.3.1)
- System.Text.Encodings.Web (>= 6.0.0)
-
net6.0
- Google.Cloud.Logging.V2 (>= 4.0.0)
- Serilog (>= 2.11.0)
- Serilog.Sinks.PeriodicBatching (>= 2.3.1)
- System.Text.Encodings.Web (>= 6.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Serilog.Sinks.GoogleCloudLogging:
Package | Downloads |
---|---|
WebPack.CoreLib
ASP.NET Core Web Pack For .NET Core; Include Default Builder; |
|
PegasusLoggingService
Package Description |
|
Findep.AspNetCore.Microservices
Core Library for FINDEP Microservices based on ASP.NET Core |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.0 | 252,394 | 6/14/2022 |
4.0.0 | 139,961 | 4/5/2022 |
3.7.0 | 94,303 | 2/20/2022 |
3.6.0 | 179,195 | 8/30/2021 |
3.5.0 | 36,880 | 6/10/2021 |
3.4.0 | 22,677 | 4/25/2021 |
3.3.3 | 51,128 | 3/15/2021 |
3.3.0 | 83,224 | 9/21/2020 |
3.2.0 | 72,172 | 6/18/2020 |
3.0.0 | 59,684 | 3/20/2020 |
2.4.1 | 2,222 | 3/18/2020 |
2.4.0 | 26,244 | 2/5/2020 |
2.3.0 | 1,902 | 1/15/2020 |
2.2.1 | 1,703 | 1/12/2020 |
2.2.0 | 27,133 | 10/8/2019 |
2.1.1 | 3,081 | 10/6/2019 |
2.1.0 | 28,342 | 9/17/2019 |
2.0.0 | 160,612 | 5/24/2019 |
1.10.0 | 47,370 | 4/4/2019 |
1.9.0 | 547 | 4/4/2019 |
1.7.0 | 81,103 | 2/8/2019 |
1.6.0 | 3,931 | 2/7/2019 |
1.5.0 | 41,375 | 10/5/2018 |
1.4.7 | 6,977 | 9/10/2018 |
1.4.6 | 14,088 | 6/2/2018 |
1.4.5 | 1,946 | 5/19/2018 |
1.4.0 | 914 | 5/19/2018 |
1.3.1 | 2,937 | 12/16/2017 |
1.3.0 | 1,264 | 12/8/2017 |
1.2.0 | 1,041 | 11/30/2017 |
1.1.0 | 1,133 | 11/28/2017 |
1.0.0 | 1,439 | 9/6/2017 |