admin管理员组

文章数量:1415119

I am learning Azure Function Apps. My function app is a timer trigger that writes logs to datadog. The issue I am facing is related to the version incompatibility.

The below works (I can see logs on Datadog):

<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Sinks.Datadog.Logs" Version="0.2.0" />

However, I want to use the latest packages and the following does not work:

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

Serilog.Sinks.Datadog.Logs version 0.5.4 should be compatible with Serilog >= 2.9.0, and Serilog.Sinks.PeriodicBatching is a transitive dependency for which the correct version is installed.

I can play around with lower versions of Serilog (>= 2.9.0, <4.2.0) to find the right fit for Serilog.Sinks.Datadog.Logs 0.5.4 and vice-versa. Can someone tell me what should be my next steps?

I am learning Azure Function Apps. My function app is a timer trigger that writes logs to datadog. The issue I am facing is related to the version incompatibility.

The below works (I can see logs on Datadog):

<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Sinks.Datadog.Logs" Version="0.2.0" />

However, I want to use the latest packages and the following does not work:

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

Serilog.Sinks.Datadog.Logs version 0.5.4 should be compatible with Serilog >= 2.9.0, and Serilog.Sinks.PeriodicBatching is a transitive dependency for which the correct version is installed.

I can play around with lower versions of Serilog (>= 2.9.0, <4.2.0) to find the right fit for Serilog.Sinks.Datadog.Logs 0.5.4 and vice-versa. Can someone tell me what should be my next steps?

Share Improve this question asked Feb 12 at 20:50 K GK G 691 silver badge10 bronze badges 5
  • Are you getting any error when you use Serilog 4.2.0? – Pravallika KV Commented Feb 13 at 3:33
  • Check if below answer helps @KG – Pravallika KV Commented Feb 18 at 4:39
  • @PravallikaKV thanks for your answer. I didn't get any error messages; however I didn't see the logs on Datadog with the versions specified above. The app used 6.0. Upgrading it to 9.0 solved the issue. – K G Commented Feb 18 at 18:50
  • Could you downgrade on your machine to 6.0 and check if you're still able to see the logs on DD? – K G Commented Feb 18 at 18:51
  • I will check and update. – Pravallika KV Commented Feb 19 at 3:33
Add a comment  | 

1 Answer 1

Reset to default 0

Create .NET 9.0 Isolated Azure function to use Serilog.Sinks.Datadog.Logs version 0.5.4 and Serilog version 4.2.0.

I have tested the same with .NET 9.0 isolated Azure function and it worked as expected.

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 Output:

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)

Serilog logs in DataDog:

本文标签: cUnable to see Datadog logs with SerilogSinksDatadogLogs Version 054 on Azure Function AppStack Overflow