用于serilolg的Graylog接收器添加http上下文数据

问题描述 投票:0回答:1

我正在尝试使用graylog接收器将日志记录添加到.net核心web api。所需的输出与控制台上的相同,使用像这样的formmater:

“[{时间戳:HH:mm:ss} {等级:u3}] {EventId} {消息:lj} {属性} {NewLine} {例外} {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接收器中看不到任何丰富的数据,并想知道如何为这个接收器提供格式化器?

.net serilog graylog2 graylog graylog3
1个回答
0
投票

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

        // 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
        };
© www.soinside.com 2019 - 2024. All rights reserved.