我正在尝试使用graylog接收器将日志记录添加到.net核心web api。所需的输出与控制台上的相同,使用像这样的formmater: “[{时间戳:HH:mm:ss} {等级:u3}] {EventId} …
为了克服这个问题我决定使用 syslog 沉入我的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 };