NorthWestNodes.Common 0.5.0

Suggested Alternatives

Web349.Logging

Additional Details

The Datadog logger within Northwest Nodes LLC-FZ has been discontinued and migrated to Web349.Logging

dotnet add package NorthWestNodes.Common --version 0.5.0
                    
NuGet\Install-Package NorthWestNodes.Common -Version 0.5.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="NorthWestNodes.Common" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NorthWestNodes.Common" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="NorthWestNodes.Common" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NorthWestNodes.Common --version 0.5.0
                    
#r "nuget: NorthWestNodes.Common, 0.5.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.
#:package NorthWestNodes.Common@0.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NorthWestNodes.Common&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=NorthWestNodes.Common&version=0.5.0
                    
Install as a Cake Tool

NorthWest Nodes common library

Nuget

The NorthWest Nodes Common Library is a class library written in C# and requires .NET Core 6.0. It contains several common functions used throughout the closed- and open-source projects at NorthWest Nodes (https://northwestnodes.com).

One of its main features is a highly flexible Datadog logger.

Installation

  • Install-Package NorthWestNodes.Common
  • dotnet add package NorthWestNodes.Common

Datadog logger

Configuration

Namespaces:

  • NorthWestNodes.Common.Logging
  • NorthWestNodes.Common.Logging.Datadog

Environment variables:

  • REQUIRED DD_API_KEY: the API key for your Datadog app.
  • REQUIRED DD_SITE: determines the intake URL. Valid options are: US1, US3, US5, US1_FED, EU.
  • OPTIONAL DD_HOST: the Host column in Datadog.
  • OPTIONAL DD_SERVICE: the Service column in Datadog.
  • OPTIONAL DD_SOURCE: the Source column in Datadog.
  • OPTIONAL DD_LOGLEVEL: the log level. Valid options are (from most verbose to none): verbose (default), debug, info, warn, error, fatal, none

Usage examples

Use the default DDLog singleton instance (note: this is not thread-safe!) to send a log message:

DDLog.Default.WriteInfo("Hello world, this is an INFO message");

Note: the single is not thread-safe and can cause issues when enriching your log messages from concurrent consumers. When using concurrent consumers, create a separate DDLog instance per consumer.

Send a basic Datadog log event:

Log log = DDLog.Create();
log.WriteInfo("An INFO log event message appearing in Datadog's message column");

Send a Datadog log event with the source set:

Log log = DDLog.Create("MySourceClassInMyProgram");
log.WriteInfo("An INFO log event specifying the class in which it was instantiated. How handy!");

Dynamic enrichtments

Send a Datadog log event with a dynamic enrichment. Dynamic enrichments get removed/reset after each Write operation:

Stopwatch sw = Stopwatch.StartNew();
// do a thing
sw.Stop();

Log log = DDLog.Create();
log
    .EnrichDynamic("responseTime", sw.ElapsedMilliseconds)
    .WriteInfo("An INFO log event message appearing in Datadog's message column");

Static enrichments

Send a Datadog log event with a static enrichment. Static enrichments do not get removed after each Write operation. Can be used in combination with Dynamic enrichtments:

Log log = DDLog.Create();
log.EnrichStatic("network", "source-network");

log
    .EnrichDynamic("someField", someVariable)
    .WriteInfo("An INFO log event message appearing in Datadog's message column");

Log levels

You can set the log level programmatically:

Log log = DDLog.Create();
log.SetLogLevel(LogLevel.Error); // only errors and up
log.WriteInfo("Hello world"); // will NOT be processed
log.WriteFatal("Ack, mein leben!"); // will be processed

Log event dispatching

The Datadog logger uses a background Task to dispatch log events in batches. By default a batch contains a maximum of 10 log events and each a maximum age of 5 seconds before being forcibly dispatched regardless of how many items a batch contains. Currently these settings are harded-coded, but you're more than welcome to submit a PR.

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 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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.

* Added the `DD_SITE` environment variable to determine the intake URL. See: https://docs.datadoghq.com/logs/log_collection/?tab=host for more information
* Downgraded to .NET 6.0 due to feedback