问题描述
将netcore项目升级到2.0之后,当我的应用程序在使用Serilog框架的AWS Lambda上运行时,我会看到重复的日志.请在下面查看我的设置:
After upgrading my netcore project to 2.0, i see double logs when my application is running on AWS Lambda, which utilizes the Serilog framework. Please see my setup below:
public void ConfigureServices(IServiceCollection services)
{
...
// Setup logging
Serilog.Debugging.SelfLog.Enable(Console.Error);
var logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext();
if (GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "").Equals("local"))
logger.WriteTo.Console();
else
logger.WriteTo.Console(new JsonFormatter());
Log.Logger = logger.CreateLogger();
...
}
和
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddSerilog();
...
}
关于为什么突然出现这种情况的任何想法? Lambda捕获所有控制台日志语句并将其插入到cloudwatch中,但是现在两次并以两种不同的格式插入.例如
Any ideas as to why this suddenly might be the case? Lambda grabs any console log statements and inserts into cloudwatch, but now twice and in two different formats. Eg.
和
我只希望日志消息以json格式格式化.这是在我升级到netcore2.0时开始的
I only expected the log message formatted in json. This started when i upgraded to netcore2.0
预先感谢
推荐答案
在Core 2.0中,日志记录实现和Serilog提供程序都发生了一些变化.
The logging implementation, and Serilog provider, have both changed a little in Core 2.0.
您将需要: https://github.com/serilog/serilog-aspnetcore 代替 Serilog.Extensions.Logging (设置说明位于README上).
You will need: https://github.com/serilog/serilog-aspnetcore instead of Serilog.Extensions.Logging (setup instructions are on the README).
这篇关于避免在带有Serilog的AWS Lambda上使用netcore2.0两次记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!