I have an ASP.NET Core 9 application controller that logs messages with warning level in Debian 12:
public class ContextLessLogger(ILogger syslog)
{
public Log()
{
syslog.Log(LogLevel.Warning, "test");
}
}
Filtering messages by warning priority produces no results:
journalctl -t MyApp -n 100 -p warning
-- No entries --
If priority filter is removed, entries are shown:
journalctl -t MyApp -n 100
produces
veebr 09 14:33:04 uvn-xxxxx.eu MyApp[3659254]: warn: Service.ContextLessLogger[0]
veebr 09 14:33:04 uvn-xxxxx.eu MyApp[3659254]: test
It looks like .NET 9 does not write warning log level to Linux log journal. How to fix this so that messages can filtered by warning priority?
Using journal based logging which is used by default in Debian 12.
Add builder.Host.UseSystemd();
and I can write warning log level to Linux log journal.
Test Result in my side.
Add builder.Host.UseSystemd();
in Program.cs, here is my sample code.
using Microsoft.Extensions.Hosting.Systemd;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Host.UseSystemd();
var app = builder.Build();
...