asp.net DataDog记录器不记录信息级别

14ifxucb  于 2023-06-07  发布在  .NET
关注(0)|答案(1)|浏览(226)

我有.NET 5 Web应用程序,它应该使用Serilog Sink(Serilog.Sinks.Datadog.Logs v0.5.2)将日志写入DataDog。下面是我的Program.cs:

static async Task Main(string[] args)
{
    using (var log = new LoggerConfiguration()
        .MinimumLevel.Verbose()
        .WriteTo.DatadogLogs("HERE IS MY API KEY", service: "myservice", configuration: new DatadogConfiguration() { Url = "https://http-intake.logs.us3.datadoghq.com" })
        .CreateLogger())
    {
        log.Debug("debug");
        log.Information("information");
        log.Verbose("verbose");
        log.Warning("warning");
        log.Error("error");
        log.Fatal("fatal");
    }

    using IHost host = CreateHostBuilder(args).Build();

    await host.RunAsync();
}

运行应用程序后,我可以在DataDog中看到所有这些日志,除了信息日志。所以,我只看到5条消息而不是6条。我做错了什么?

l7wslrjt

l7wslrjt1#

我认为问题在于您设置的是Serilog日志事件级别,而不是Datadog级别。试试这个:

.WriteTo.DatadogLogs("HERE IS MY API KEY", 
        service: "myservice",
        logLevel: LogEventLevel.Information,
        configuration: new DatadogConfiguration() { 
            Url = "https://http-intake.logs.us3.datadoghq.com" }
    )

相关问题