I agree with @Ziya Mert Karakas
But, I have used simple another workaround.
You can use "logLevel" in your host.json to send the logs in your traces table in application insights. If you do not use loglevel by default it is set to use Information level.

In My host.json, I have set it to "Warning" so I will get warning level and higher logs.
host.json:
{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Warning"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}
I have Created a simple timer trigger to send log to Datadog and application insights.
Function.cs:
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using Serilog;
using System;
public static class Function1
{
[Function("MyFunction")]
public static void Run(
[TimerTrigger("*/30 * * * * *")] FunctionContext context)
{
// Log using Serilog
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");
// Log using the ILogger provided by Azure Functions
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:
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Sinks.Datadog.Logs;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
// Configure Serilog for Datadog
Log.Logger = new LoggerConfiguration()
.WriteTo.DatadogLogs(apiKey: "xxxxxxxxxxxx")
.CreateLogger();
})
.Build();
host.Run();
Output:
Without using : loglevel
other trace log are also available.




With : logLevel
only logs which is equal or higher severityLevel of Warning are available.



For Reference check this MS Doc.