Categories: .NET Core

How To Create And Use Custom Tags In DataDog Log Using Asp.net Core Web API.

In this blog, we will talk about creating custom tags in the Datadog log, and also we will discuss how to send hostname, service name, and log template in the Datadog.

you can watch my previous blog on how to send logs in asp.net core web API. here

Firstly, You can create an account in Datadog and get the API key. If you haven’t, you can see my previous blog.

  • Creating a DataDog account and getting the API key. Link
  • Datadog Log Integration In Asp.Net Core Web API. Link

Let’s start,

To send your C# logs to Datadog, we recommend logging into a file and then tailing that file with your Datadog site. Here are setup examples for the  SerilogNLog, and log4net logging libraries.

In this article, we are going with Agentless logging. In Agentless logging we are using Serilog. 

Install the Datadog Serilog sink, which sends events and logs to Datadog. By default, the sink forwards logs through HTTPS on port 443. Run the following command in the Package Manager Console:

PM> Install-Package Serilog.Sinks.Datadog.Logs

Then, initialize the logger directly in your application. Do not forget to add your <API_KEY>.

using (var log = new LoggerConfiguration()
    .WriteTo.DatadogLogs(
        "<API_KEY>",
         host: "<HOST_NAME>",
         source: "<SOURCE_NAME>",
         service: "<SERVICE_NAME>",
         tags: new string[] {"<TAG_1>:<VALUE_1>", "<TAG_2>:<VALUE_2>"}
    )
    .CreateLogger())
{
   Exception ex = new Exception();
   var message = "this is log message";
   
   //Error Log
    log.Error("Error Message {@ErrorMessage}, Exception {@Exception} ", message, ex);
   //Info Log
    log.Information("Info Message {@Message}", message);
   //Warning Log
    log.Warning("Warning Message {@Message}", message);
}

New logs are now directly sent to Datadog.

You can see in the above image hostname, service name, source name, and error message. In this log management dashboard, you can search with your tag name and filter the log. you can create your own error template as per your requirement.

I hope you guys understand how I can do this.  Let me know if you face any difficulties.

You can watch my previous blog here. and next blog.

Happy Coding {;} ????

Nayan Raval

Nayan Raval is a MEAN Stack .Net Developer has extensive experience with designing and developing enterprise-scale applications. Key Areas Of Expertise: • ASP.NET Core MVC • ASP.NET Core Web API • C# • ASP.NET MVC 5 • Angular All versions • HTML5 • CSS3 / SCSS • Bootstrap • JavaScript • Azure • JQuery Databases and related • Microsoft SQL server MSSQL • PostgreSQL • Entity Framework (EF) • LINQ UI Frameworks • Kendo UI • Telerik • JQuery UI • Prime NG and Material UI API Integration • SignalR • DateDog • Twilio Voice Call And Message • Stripe • SendGrid (Email Camping) • Checkr • Zoom Video Call • Auth0 • Elastic Search • Quartz - Scheduler • JWT Token • Google Calendar

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago