简体   繁体   English

带有 Serilog 控制台接收器的 Cloudwatch 显示在带有 do.net 的单个 cloudwatch 条目中 lambda

[英]Cloudwatch with Serilog console sink showing in single cloudwatch entry with dotnet lambda

I am trying to use Serilog console sink to write to cloudwatch.我正在尝试使用 Serilog 控制台接收器写入 cloudwatch。 Yet when using Log.Information or Log.Error they are appearing in cloudwatch as one entry.然而,当使用 Log.Information 或 Log.Error 时,它们作为一个条目出现在 cloudwatch 中。

Additionally, an exception trace will show as separate entries.此外,异常跟踪将显示为单独的条目。 I have tried changing the output template but this hasn't worked for info the serilog config is我试过更改 output 模板,但这对 serilog 配置的信息不起作用

"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"MinimumLevel": "Information",
"WriteTo": [
  {
    "Name": "Console",
    "Args": {
      "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] <{SourceContext}> {Message:lj}\r{Exception}"
    }
  }
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]

} }

Serilog log entries in same cloudwatch log event同一 cloudwatch 日志事件中的 Serilog 日志条目

TL;DR;长话短说;博士; Don't use the Console sink for that.不要为此使用控制台接收器。 Use the AWS.Logger.SeriLog sink instead.请改用AWS.Logger.SeriLog 接收器。


The Console sinks is not the right tool for this job and you are not really sending logs to CloudWatch at the moment... You're just sending text. Console sinks 不是这项工作的正确工具,您目前并没有真正向 CloudWatch 发送日志……您只是发送文本。 You're writing text to the Console and the raw console output is being captured by your environment and are then being forwarded to ClowdWatch as text as they get written to the output stream...您正在向控制台写入文本,原始控制台 output 正在被您的环境捕获,然后在写入 output stream 时作为文本转发到 ClowdWatch...

In order to properly send Serilog logs to AWS CloudWatch, you need to use a sink that will write logs to AWS CloudWatch directly, such as AWS.Logger.SeriLog which is the official sink supported by AWS.为了将 Serilog 日志正确发送到 AWS CloudWatch,您需要使用将日志直接写入 AWS CloudWatch 的接收器,例如AWS.Logger.SeriLog ,这是 AWS 支持的官方接收器。

AWSLoggerConfig configuration = new AWSLoggerConfig("Serilog.ConfigExample");
configuration.Region = "us-east-1";

Log.Logger = new LoggerConfiguration()
    .WriteTo.AWSSeriLog(configuration)
    .CreateLogger();

The source code repo is https://github.com/aws/aws-logging-do.net#serilog and there are usage examples on https://github.com/aws/aws-logging-do.net/tree/master/samples/Serilog源代码 repo 是https://github.com/aws/aws-logging-do.net#serilog并且在https://github.com/aws/aws-logging-do.net/tree/上有使用示例主/样本/Serilog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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