当Serilog在IIS / Visual Studio(.netCore 3.1)中本地运行时,我可以正常工作,但是当我将其部署到AWS Lambda时,应用程序无法启动,并且在CloudWatch日志中出现以下错误:
System.InvalidOperationException:尝试激活“ Serilog.AspNetCore.RequestLoggingMiddleware”时无法解析“ Serilog.Extensions.Hosting.DiagnosticContext”类型的服务
任何想法意味着什么或如何解决它?
已修改以显示代码:
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
try
{
Log.Information("Starting up");
CreateHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application start-up failed");
}
finally
{
Log.CloseAndFlush();
}
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});