首页 > 解决方案 > 从 aspnet 核心应用程序到 cloudwatch 的详细应用程序日志

问题描述

我对 cloudwatch 中的应用程序日志有一些问题。

我正在使用 dotnet core 和 Elastic 容器服务,并将 cloudwatch 设置为应用程序日志,但日志仅输出如下启动:

但是当我在本地运行应用程序时,应用程序日志更详细,并显示抛出如下异常: 在此处输入图像描述

我使用 serilog 并像这样设置它:

    private void ConfigureSeriLog()
    {
        Log.Logger = new LoggerConfiguration()
            .ReadFrom.Configuration(Configuration)
            .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
            .MinimumLevel.Information()
            .Enrich.FromLogContext()
            .WriteTo.Console()
            .CreateLogger();
    }

    public void ConfigureServices(IServiceCollection services)
    {
        [...]
        services.AddLogging(loggingBuilder =>
            loggingBuilder.AddSerilog(dispose: true));
         [...]
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
        ILoggerFactory loggerFactory,
        IApplicationLifetime appLifetime)
    {
        [...]
        loggerFactory.AddSerilog();
        appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);
        [...]
    }

还有我的 appsettings.json(我在这个文件中尝试了很多不同的组合):

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

这是很多。但如果有人能指出我正确的方向,我会很高兴。任何有关如何使用 cloudwatch 和 aspnet 核心设置详细应用程序日志的教程或提示将不胜感激:)

标签: asp.net-coreserilogamazon-cloudwatchlogs

解决方案


我不是该主题的专家,但我认为您需要在 loggerConfiguration 中添加 .WriteTo.AmazonCloudWatch(options, client)。


推荐阅读