NorthWestNodes.Common
0.5.0
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
<PackageReference Include="NorthWestNodes.Common" Version="0.5.0" />
paket add NorthWestNodes.Common --version 0.5.0
#r "nuget: NorthWestNodes.Common, 0.5.0"
// Install NorthWestNodes.Common as a Cake Addin
#addin nuget:?package=NorthWestNodes.Common&version=0.5.0
// Install NorthWestNodes.Common as a Cake Tool
#tool nuget:?package=NorthWestNodes.Common&version=0.5.0
NorthWest Nodes common library
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
: theHost
column in Datadog. - OPTIONAL
DD_SERVICE
: theService
column in Datadog. - OPTIONAL
DD_SOURCE
: theSource
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 | Versions 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. |
-
net6.0
- System.Configuration.ConfigurationManager (>= 6.0.1)
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 | |
---|---|---|---|
0.5.0 | 389 | 2/19/2023 | |
0.4.5 | 239 | 2/19/2023 | |
0.4.4 | 253 | 2/17/2023 | |
0.4.3 | 237 | 2/17/2023 | |
0.4.2 | 240 | 2/17/2023 | |
0.4.1 | 244 | 2/17/2023 | |
0.4.0 | 234 | 2/17/2023 | |
0.4.0-beta1 | 127 | 2/17/2023 | |
0.3.1-beta1 | 142 | 9/30/2022 | |
0.2.4-beta1 | 143 | 8/17/2022 | |
0.2.3-beta1 | 145 | 8/17/2022 | |
0.2.1-beta1 | 142 | 8/17/2022 | |
0.2.0-beta1 | 144 | 8/15/2022 | |
0.1.2-beta1 | 129 | 8/15/2022 | |
0.1.1-beta1 | 140 | 8/15/2022 | |
0.1.0-beta1 | 143 | 8/12/2022 |
* 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