DataDog / serilog-sinks-datadog-logs

Serilog Sink that sends log events to Datadog https://www.datadoghq.com/
Apache License 2.0
60 stars 41 forks source link

I can't get it to work #102

Closed Jay-H-C closed 1 year ago

Jay-H-C commented 1 year ago

I am trying to do Agentless logging trying to have a direct upload to Datadog without saving it as a file. but it does not work, Datadog is waiting for a log forever.

gh123man commented 1 year ago

Hi @Jay-H-C

Can you please provide:

  1. An example of your configuration
  2. a copy of any error logs you my have (note: you may need to configure exceptionHandler to catch errors)
Jay-H-C commented 1 year ago

Thank you for the response here is what I have.

My config in the appsettings.json

"Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Datadog.Logs" ],
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "DatadogLogs",
        "Args": {
          "apiKey": "0acb20eec6f3d4-----------------",
          "source": "Test",
          "host": "DEV_MACHINE",
          "tags": [ "TAG_1:VALUE_1", "TAG_2:VALUE_2" ]
        }
      }
    ],
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
    "Properties": {
      "Application": "Sample"
    }
  }

and my code:

using (var log = new LoggerConfiguration()
                    .WriteTo.DatadogLogs("0acb20eec6f3d4-----------------", configuration: new DatadogConfiguration() { Url = "https://http-intake.logs.us5.datadoghq.com" })
                    .CreateLogger())
            {
                log.Information("TEST LOG");

                log.Error("TEST LOG ERROR");
            }

What am I doing wrong? I am not getting any exceptions.

Thank you!

Jay-H-C commented 1 year ago

This is the exception I got by hooking up the exception handler:

Could not send payload to Datadog: [Forbidden] Forbidden - [{"ddsource":"csharp","message":"{\"timestamp\":\"2023-07-17T08:26:14.5418598-07:00\",\"message\":\"TEST LOG\",\"MessageTemplate\":\"TEST LOG\",\"level\":\"Information\",\"Properties\":{}}"},{"ddsource":"csharp","message":"{\"timestamp\":\"2023-07-17T08:26:14.5456529-07:00\",\"message\":\"TEST LOG ERROR\",\"MessageTemplate\":\"TEST LOG ERROR\",\"level\":\"Error\",\"Properties\":{}}"}].

Jay-H-C commented 1 year ago

Okay I switched to the default repo my removing the US5 address and I am seeing my logs.

Thank you!