我决定将 AWS cloudwatch 登录添加到我的应用程序中,但似乎有问题。有很多网站描述了如何将 Serilog 接收器添加到 AWS 云手表,我使用了 2 个不同的版本,在所有情况下,当我想启动应用程序时,我都会收到这条消息。
An unhandled exception of type 'System.MissingMethodException' occurred in WebApplication3.dll
Method not found: 'Serilog.LoggerConfiguration Serilog.Configuration.LoggerSinkConfiguration.Sink(Serilog.Core.ILogEventSink, Serilog.Events.LogEventLevel)'.
一旦我将
.WriteTo.AWSSeriLog
或 .WriteTo.AmazonCloudWatch
添加到我的 serilog 配置中,就会发生这种情况。下面是我使用的示例代码
using Serilog.Events;
using Serilog;
using ILogger = Serilog.ILogger;
using AWS.Logger.SeriLog;
using AWS.Logger;
using Amazon.Runtime;
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build();
var builder = WebApplication.CreateBuilder(args);
var awsLoggerConfig = new AWSLoggerConfig()
{
Region = config["AWS:Region"],
LogGroup = "/dotnet/logging-demo/serilog",
LogStreamNamePrefix = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff"),
Credentials = new BasicAWSCredentials(config["AWS:AccessKey"], config["AWS:SecretKey"])
};
builder.Logging.ClearProviders();
ILogger logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.AWSSeriLog(awsLoggerConfig, restrictedToMinimumLevel: LogEventLevel.Warning)
.WriteTo.Console()
.CreateLogger();
builder.Logging.AddSerilog(logger);
你知道我怎么解决这个问题吗?应用程序正在 .net 7.
上运行我已经在 2 台装有 Win 11 和 Win 10 的不同机器上对此进行了测试。