Serilog.Sinks.Datadog.Logs
0.5.4
dotnet add package Serilog.Sinks.Datadog.Logs --version 0.5.4
NuGet\Install-Package Serilog.Sinks.Datadog.Logs -Version 0.5.4
<PackageReference Include="Serilog.Sinks.Datadog.Logs" Version="0.5.4" />
paket add Serilog.Sinks.Datadog.Logs --version 0.5.4
#r "nuget: Serilog.Sinks.Datadog.Logs, 0.5.4"
// Install Serilog.Sinks.Datadog.Logs as a Cake Addin #addin nuget:?package=Serilog.Sinks.Datadog.Logs&version=0.5.4 // Install Serilog.Sinks.Datadog.Logs as a Cake Tool #tool nuget:?package=Serilog.Sinks.Datadog.Logs&version=0.5.4
Serilog.Sinks.Datadog.Logs
A Serilog sink that send events and logs straight away to Datadog. By default the sink sends logs over HTTPS
Package - Serilog.Sinks.Datadog.Logs | Platforms - .NET 4.5, .NET 4.6.1, .NET 4.7.2, netstandard1.3, netstandard2.0
Note: For other .NET versions, ensure that the default TLS version used is 1.2
using (var log = new LoggerConfiguration()
.WriteTo.DatadogLogs("<API_KEY>")
.CreateLogger())
{
// Some code
}
By default the logs are forwarded to Datadog via HTTPS on port 443 to the US site.
You can change the site to EU by using the url
property and set it to https://http-intake.logs.datadoghq.eu
.
You can override the default behavior and use TCP forwarding by manually specifing the following properties (url, port, useSSL, useTCP).
You can also add the following properties (source, service, host, tags) to the Serilog sink.
- Example with a TCP forwarder which add the source, service, host and a list of tags to the logs:
var config = new DatadogConfiguration(url: "intake.logs.datadoghq.com", port: 10516, useSSL: true, useTCP: true);
using (var log = new LoggerConfiguration()
.WriteTo.DatadogLogs(
"<API_KEY>",
source: "<SOURCE_NAME>",
service: "<SERVICE_NAME>",
host: "<HOST_NAME>",
tags: new string[] {"<TAG_1>:<VALUE_1>", "<TAG_2>:<VALUE_2>"},
configuration: config
)
.CreateLogger())
{
// Some code
}
Example
Sending the following log:
using (var log = new LoggerConfiguration()
.WriteTo.DatadogLogs("<API_KEY>")
.CreateLogger())
{
// An example
var position = new { Latitude = 25, Longitude = 134 };
var elapsedMs = 34;
log.Information("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);
}
or
Log.Logger = new LoggerConfiguration()
.WriteTo.DatadogLogs("<API_KEY>")
.CreateLogger();
// An example
var position = new { Latitude = 25, Longitude = 134 };
var elapsedMs = 34;
Log.Information("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);
Log.CloseAndFlush();
In the platform, the log looks like as the following JSON Object:
{
"message": "Processed { Latitude: 25, Longitude: 134 } in 034 ms.",
"MessageTemplate": "Processed {@Position} in {Elapsed:000} ms.",
"timestamp": "2022-11-23T09:48:56.0262350-05:00",
"level": "Information",
"Properties": {
"Position": {
"Latitude": 25,
"Longitude": 134
},
"Elapsed": 34
},
"Renderings": [
"034"
]
}
Configuration from appsettings.json
Since 0.2.0, you can configure the Datadog sink by using an appsettings.json
file with
the Serilog.Settings.Configuration package.
In the "Serilog.WriteTo"
array, add an entry for DatadogLogs
. An example is shown below:
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Datadog.Logs" ],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" },
{
"Name": "DatadogLogs",
"Args": {
"apiKey": "<API_KEY>",
"source": "<SOURCE_NAME>",
"host": "<HOST_NAME>",
"tags": ["<TAG_1>:<VALUE_1>", "<TAG_2>:<VALUE_2>"],
"configuration" : {
"url": "intake.logs.datadoghq.com",
"port": 10516,
"useSSL": true,
"useTCP": true
}
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "Sample"
}
}
NOTE: the configuration
section is optional so that you may override the defaults.
Using a custom log formatter
You can implement a custom ITextFormatter
and pass it to the sink to change the format of your logs. This is useful if you want to add/remove/modify fields from the final JSON payload, or emit non-json logs to Datadog.
There are several options for implementing custom formatters. The easiest way is to use Serilog-expressions. Below is an example of a Serilog-expression ITextFormatter
that drops the MessageTemplate
field:
public class DatadogJsonNoTemplateFormatter: ExpressionTemplate
{
public DatadogJsonNoTemplateFormatter() : base(@"{ {
Timestamp: @t,
level: @l,
message: @m,
Properties: {..@p},
Renderings: @r}
}") {}
}
If you cannot use Serilog-expressions due to framework compatibility - you can implement your own with JsonValueFormatter
or a default implementation ex: serilog-formatting-compact
Support Configuration Options
DatadogLogs
supports the following arguments:
argument | Type | Description |
---|---|---|
apiKey |
string |
Your Datadog API key. |
source |
string |
The integration name. |
service |
string |
The service name. |
host |
string |
The host name. |
tags |
string[] |
Custom tags. |
configuration |
DatadogConfiguration |
The Datadog logs client configuration. |
restrictedToMinimumLevel |
LogEventLevel |
The minimum log level for the sink. |
batchSizeLimit |
int |
The maximum number of events to emit in a single batch. |
batchPeriod |
TimeSpan |
The time to wait before emitting a new event batch. |
queueLimit |
int |
Maximum number of events to hold in the sink's internal queue, or null for an unbounded queue. The default is 10000 |
exceptionHandler |
Action<Exception> |
This function is called when an exception occurs when using DatadogConfiguration.UseTCP=false (the default configuration). |
detectTCPDisconnection |
bool |
Detect when the TCP connection is lost and recreate a new connection. |
formatter |
ITextFormatter |
A custom formatter implementation to change the format of the logs |
maxMessageSize |
int |
The maximum size in bytes of a message before it is split into chunks |
NOTE: if maxMessageSize
exceeds the documented API limit of 1MB - any payloads larger than 1MB will be dropped by the intake.
How to build the NuGet package
Bump the version in src/Serilog.Sinks.Datadog.Logs.csproj
and merge your branch
Run these commands in the project root folder
git checkout master && git pull
msbuild Serilog.Sinks.Datadog.Logs.sln /t:restore /p:Configuration=Release
msbuild Serilog.Sinks.Datadog.Logs.sln /t:pack /p:Configuration=Release
You can find the .nupkg
file at src/Serilog.Sinks.Datadog.Logs/bin/Release/Serilog.Sinks.Datadog.Logs.<version>.nupkg
Serilog.Sinks.Async
As Serilog.Sinks.Datadog.Logs
implements Serilog.Sinks.PeriodicBatching, using Serilog.Sinks.Async is not recommended.
From Serilog.Sinks.Async documentation:
Note: many of the network-based sinks (CouchDB, Elasticsearch, MongoDB, Seq, Splunk...) already perform asynchronous batching natively and do not benefit from this wrapper.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- Serilog (>= 2.9.0)
- Serilog.Sinks.PeriodicBatching (>= 3.1.0)
- System.Net.Http (>= 4.3.4)
-
.NETFramework 4.6.1
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.1.1)
- Serilog (>= 2.9.0)
- Serilog.Sinks.PeriodicBatching (>= 3.1.0)
-
.NETFramework 4.7.2
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.1.1)
- Serilog (>= 2.9.0)
- Serilog.Sinks.PeriodicBatching (>= 3.1.0)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- Serilog (>= 2.9.0)
- Serilog.Sinks.PeriodicBatching (>= 3.1.0)
- System.Net.Http (>= 4.3.4)
- System.Net.Security (>= 4.3.2)
- System.Net.Sockets (>= 4.3.0)
- System.Threading.Thread (>= 4.3.0)
-
.NETStandard 2.0
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.1.1)
- Serilog (>= 2.9.0)
- Serilog.Sinks.PeriodicBatching (>= 3.1.0)
-
net5.0
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.1.1)
- Serilog (>= 2.9.0)
- Serilog.Sinks.PeriodicBatching (>= 3.1.0)
NuGet packages (14)
Showing the top 5 NuGet packages that depend on Serilog.Sinks.Datadog.Logs:
Package | Downloads |
---|---|
Serilog.Builder
Builder with my serilog common settings for use Console, Seq and Splunk sinks. |
|
MarketplaceStack.Operations
SP API Operations |
|
Prospa.Extensions.Hosting
.NET Core Hosting Extensions. |
|
SnD.Sdk
SDK for Sneaks&Data OSS Projects |
|
ReinsuranceLibrary.LoggerManager
Functional library for .Net. Obrigatório o uso das variaveis de ambiente "LogGroupName" e "Application" |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.5.4 | 13,177 | 11/13/2024 |
0.5.3 | 246,019 | 9/18/2024 |
0.5.2 | 5,462,058 | 3/14/2023 |
0.5.1 | 761,125 | 1/13/2023 |
0.5.0 | 113,800 | 1/3/2023 |
0.4.1-beta1 | 7,553 | 12/5/2022 |
0.4.0 | 319,790 | 11/25/2022 |
0.3.8 | 1,274,633 | 10/5/2022 |
0.3.7 | 1,113,399 | 6/30/2022 |
0.3.6 | 2,221,492 | 2/11/2022 |
0.3.5 | 2,764,564 | 9/8/2021 |
0.3.4 | 2,575,595 | 12/2/2020 |
0.3.3 | 684,394 | 9/24/2020 |
0.3.2 | 782,307 | 7/8/2020 |
0.3.1 | 933,692 | 1/29/2020 |
0.3.0 | 594,439 | 4/11/2019 |
0.2.0 | 95,528 | 2/5/2019 |
0.1.5 | 6,846 | 1/10/2019 |
0.1.4 | 9,200 | 11/2/2018 |
0.1.3 | 46,415 | 7/30/2018 |