1

I have a Web API and I'm trying to log messages into Graylog, using Serilog. Now matter what I do, no messages are shown in my Graylog application. This is what I have so far:

This is in my Program.cs

var logger = new LoggerConfiguration().
    ReadFrom.Configuration(builder.Configuration).
    Enrich.FromLogContext().
    CreateLogger();

builder.Logging.ClearProviders();
builder.Logging.AddSerilog(logger);

This is my configuration:


  "Serilog": {
    "Using": [ "Serilog.Sinks.Graylog" ],
    "MinimumLevel": "Information",
    "WriteTo": [
      {
        "Name": "Graylog",
        "Args": {
          "hostnameOrAddress": "127.0.0.1",
          "port": "12201",
          "transportType": "Udp"
        }
      }
    ],
    "Properties": {
      "Application": "Centralized logging application"
    }
  },
  "AllowedHosts": "*"
}

And I'm trying to log a:

_logger.LogError(0, new Exception("Exception Message"), "Message", new WeatherForecast());

Can someone please help me? I need to see my exception inside Graylog.

Thanx a lot in advance

Katia S.
  • 197
  • 2
  • 13

2 Answers2

1

Your configuration is correct. Now you need to configure the Graylog side as the colleague above asked. To do this, go to the Graylog interface, more specifically at: System/Inputs -> Inputs. Then, create a GELF UDP entry with the respective port of your Graylog.

Fabio Alves
  • 91
  • 1
  • 10
0

Do you have the input set up on the Graylog side? Have you verified that you can get messages to that input?

Finally, I noticed you were sending it to local host. Are both applications on the same machine? If not, you will want to put in the address of the Graylog server.

Blackbox
  • 59
  • 3
  • Yes both my App and the Graylog server run in my localhost. As far as the "input" is concerned, I don't know what you mean. What input? – Katia S. May 20 '22 at 08:28