1

I am trying to add logging to .net core web api using graylog sink. The desired output is to have same as on the console using formmater like this one:

"[{Timestamp:HH:mm:ss} {Level:u3}] {EventId} {Message:lj} {Properties}{NewLine}{Exception}{NewLine}")

which produces that output:

[18:10:03 INF] { Id: 2 } Request finished in 876.4304ms 200 
text/plain; charset=utf-8 {ElapsedMilliseconds=876.4304, 
StatusCode=200, ContentType="text/plain; charset=utf-8", 
SourceContext="Microsoft.AspNetCore.Hosting.Internal.WebHost", 
RequestId="0HLL72NNJ19OK:00000001", RequestPath="/geo/allmenu", 
CorrelationId=null, ConnectionId="0HLL72NNJ19OK"}

My sink configuration for graylog :

  var graylogConfig = new GraylogSinkConfiguration
        {

            Host = "10.1.1.100",
            Port = 12201,
            UseSecureConnection = false,
            UseAsyncLogging = true,
            GraylogTransportType = GraylogTransportType.Tcp,
            RetryCount = 20,
            PropertyPrefix = "webapi",                

        };

Unfortunately, I cannot see any enriched data in graylog sink and wondering how I could provide formatter for this sink?

profesor79
  • 9,213
  • 3
  • 31
  • 52

1 Answers1

0

to overcome this issue I decided to use syslog sink in my asp.net core app, that allows me to have all enriched log data attached.

        // Use custom message template formatters, just so we can distinguish which sink wrote each message
        var tcpTemplateFormatter = new MessageTemplateTextFormatter("[{Timestamp:HH:mm:ss} {Level:u3}] {EventId} {Message:lj} {Properties}{NewLine}{Exception}{NewLine}{Message}", null);


        // Log RFC5424 formatted events to a syslog server 
        var tcpConfig = new SyslogTcpConfig
        {
            Host = "10.1.1.100",
            Port = 12201,
            Formatter = new Rfc5424Formatter(templateFormatter: tcpTemplateFormatter),
            Framer = new MessageFramer(FramingType.OCTET_COUNTING),
            KeepAlive = true
        };
profesor79
  • 9,213
  • 3
  • 31
  • 52