简体   繁体   中英

Serilog with Graylog not logging

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM