serilog-extensions-hosting
serilog-extensions-hosting copied to clipboard
Azure Isolated Function does not route logs to serilog
nothing that the function framework outputs ends up in serilog. This could be exceptions from any host extension like sqlTrigger.
Any injection of ILogger does work as expected.
Reproduction: ``func init
That gives you a base function project. Change program.cs to:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
services.AddSerilog(Log.Logger);
})
.Build();
host.Run();
When you run it you will see lots of output on the console screen - and none of that ends up in seq (did not go through serilog).
Add a function to the project (and the Microsoft.Azure.Functions.Worker.Extensions.Sql package):
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Sql;
namespace Company.FunctionApp1;
public static class SqlTrigger
{
[Function("SomeTrigger")]
public static void Run(
[SqlTrigger("[dbo].[SomeTable]", "Main.ConnectionString")]
FunctionContext context)
{
}
}
Run that and you will see lots more logs and errors about the connection string not being valid - again none of that is in seq.
There are logs in seq (going thru serilog) in the above example from Microsoft.AspNetCore.DataProtection and Microsoft.Hosting, etc - so that part of the serilog works - but anything from function app does not.
Not sure if this is an issue with logging not setup properly by AddSerilog or if this is an issue with https://github.com/Azure/azure-functions-host or https://github.com/Azure/azure-webjobs-sdk
Thoughts?