I'm relatively new to C# and Azure and this thing confuses me to no end. What I want is to log everything Information+ to Seq, and to override MS/System to Warning+.
Startup.cs
using System;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Serilog.Events;
[assembly: FunctionsStartup(typeof(SillyApp.Startup))]
namespace SillyApp
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Warning)
.WriteTo.Seq("https://blahblah.bla")
.CreateLogger();
builder.Services.AddLogging(b => { b.AddSerilog(logger); });
}
}
}
My understanding is that I've now added a Serilog-provider to the logging Providers. This works in that Seq receives, but the overrides does nothing. The Minimumlevel.Information does work however.
SillyApp.cs
using System;
using System.Text;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace SillyApp
{
public class MyClass
{
private ILogger<MyClass> _logger;
public MyClass(ILogger<MyClass> log)
{
_logger = log;
}
[FunctionName("TimedThing")]
public async Task RunAsync([TimerTrigger("*/10 * * * * *")] TimerInfo timer)
{
_logger.LogInformation("Helloes");
}
}
}
My theory is that logging providers now include both the default one and the Serilog one. And somehow they combine and make my life a misery. What shows up in Seq is a whole bunch of stuff. Executed messages, "1 function loaded", "Host Initialized/started". Tagged as Information, but doesn't even show in my Run Window.
So if my theory is correct, how do I override the default logging provider? If I'm mistaken then can someone please tell me what's going on?