K G
K G

Reputation: 69

Unable to see Datadog logs with Serilog.Sinks.Datadog.Logs Version 0.5.4 on Azure Function App

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.

enter image description here

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?

Upvotes: 0

Views: 49

Answers (1)

Pravallika KV
Pravallika KV

Reputation: 8694

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:

enter image description here

Upvotes: 0

Related Questions