无法在Azure函数上使用Serilog.sinks.datadog.logs版本0.5.4查看DataDog日志 我正在学习Azure函数应用程序。我的功能应用程序是将日志写入DataDog的计时器触发器。我面临的问题与版本不兼容有关。 以下作品(我可以在

问题描述 投票:0回答:1

,但是,我想使用最新的软件包,以下内容不起作用:

<PackageReference Include="Serilog" Version="4.2.0" /> <PackageReference Include="Serilog.Sinks.Datadog.Logs" Version="0.5.4" />

Serilog.sinks.datadog.logs版本0.5.4应与Serilog> = 2.9.0兼容,而Serilog.Sinks.sinks.periodicbatching是安装正确版本的传递依赖性。


i可以使用较低版本的

Serilog

(> = 2.9.0,Serilog.Sinks.Datadog.Logsenter image description here0.5.4,反之亦然。 有人可以告诉我应该是我的下一步吗?

Create

.net9.0隔离的Azure函数
使用<4.2.0) to find the right fit for
Serilog.Sinks.Datadog.Logs
版本

0.5.4
c# azure-functions serilog datadog
1个回答
0
投票
Serilog

版本4.2.0.

I与.NET 9.0隔离的Azure函数进行了测试,并且可以按预期工作。
public static class Function1
{
    [Function("MyFunction")]
    public static void Run(
        [TimerTrigger("0 */2 * * * *")] FunctionContext context)
    {
        // Serilog logs
        Log.Information("C# Timer trigger function executed at: {time}", DateTime.Now);
        Log.Information("Time in UTC: {time}", DateTime.UtcNow);
        Log.Information("This is Datadog LOG");

        // ILogger logs
        var logger = context.GetLogger("Function1");
        logger.LogInformation("This is an Azure Functions log message.");
        logger.LogWarning("This is a Warning message");
        logger.LogError("this is a error message");

    }
}
PROGRAM.CS:

var host = new HostBuilder() .ConfigureFunctionsWebApplication() .ConfigureServices(services => { Log.Logger = new LoggerConfiguration() .WriteTo.DatadogLogs(apiKey: "<DataDog_APIKey>") .CreateLogger(); }) .Build(); host.Run();

 -host.json:

{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" }, "enableLiveMetricsFilters": true } } } Console输出:

Functions:

        MyFunction: timerTrigger

For detailed output, run func with --verbose flag.
[2025-02-13T07:39:57.306Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2025-02-13T07:40:00.072Z] Executing 'Functions.MyFunction' (Reason='Timer fired at 2025-02-13T13:10:00.0440887+05:30', Id=55026381-b0a8-4f7b-ad00-d18ae8656991)
[2025-02-13T07:40:00.194Z] This is an Azure Functions log message.
[2025-02-13T07:40:00.198Z] This is a Warning message
[2025-02-13T07:40:00.199Z] this is a error message
[2025-02-13T07:40:00.223Z] Executed 'Functions.MyFunction' (Succeeded, Id=55026381-b0a8-4f7b-ad00-d18ae8656991, Duration=169ms)

dataDog中的serilog日志:


    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.