1

我正在尝试使用 graylog sink 将日志记录添加到 .net core web api。所需的输出与使用以下格式的控制台上的输出相同:

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

产生该输出:

[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"}

我的 graylog 接收器配置:

  var graylogConfig = new GraylogSinkConfiguration
        {

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

        };

不幸的是,我在 graylog 接收器中看不到任何丰富的数据,并且想知道如何为这个接收器提供格式化程序?

4

1 回答 1

0

为了克服这个问题,我决定syslog在我的 asp.net 核心应用程序中使用 sink,它允许我附加所有丰富的日志数据。

        // 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
        };
于 2019-03-13T11:41:11.210 回答