Serilog.Sinks.LazyGoogleCloudLogging 1.0.0

dotnet add package Serilog.Sinks.LazyGoogleCloudLogging --version 1.0.0                
NuGet\Install-Package Serilog.Sinks.LazyGoogleCloudLogging -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Serilog.Sinks.LazyGoogleCloudLogging" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Sinks.LazyGoogleCloudLogging --version 1.0.0                
#r "nuget: Serilog.Sinks.LazyGoogleCloudLogging, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Serilog.Sinks.LazyGoogleCloudLogging as a Cake Addin
#addin nuget:?package=Serilog.Sinks.LazyGoogleCloudLogging&version=1.0.0

// Install Serilog.Sinks.LazyGoogleCloudLogging as a Cake Tool
#tool nuget:?package=Serilog.Sinks.LazyGoogleCloudLogging&version=1.0.0                

Serilog.Sinks.GoogleCloudLogging

Serilog sink that writes events to Google Cloud Logging.

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();

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 a JSON string (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.
  • GCP Error Reporting is separate from Cloud Logging and will automatically capture error messages only if they have an Exception attached. It is not based on log severity level.
  • 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 JSON string to override Application Default Credentials (contents of your 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 Compatible and additional computed target framework versions.
.NET 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 65 12/17/2024