Home
> Uncategorized > Record events to #DataDog with .NET Core / C#
Record events to #DataDog with .NET Core / C#

Datadog is a powerful logging tool, great for keeping an eye on servers that may not always have a pretty admin tool.
Here is a code example in C# on how to record an event to DataDog via it’s API. Here I have used my own API Key, (feel free to mess about, I don’t intend to use this account seriously), but evidently, you should get your own API key.
TL;DR – Getting ot the point, here is the Github repo if you don’t want to read – https://github.com/infiniteloopltd/DataDogCSharpCore
Here is the code I used;
const string key = "f15d23159b008e325e2cf65a04502c05";
var url = "https://api.datadoghq.eu/api/v1/events?api_key=" + key; // EU api endpoint
var oReq = new
{
text= "This is the event body",
title = "This is the event title"
};
var strReq = JsonConvert.SerializeObject(oReq);
var wc = new WebClient();
try
{
var response = wc.UploadString(url, strReq);
Console.WriteLine(response);
}
catch (WebException wex)
{
var err = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine(err);
}
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback