-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
ASP.NET Core 9 MVC application runs as a service in Debian and logs into a journal.
Program.cs
:
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();
...
Logging from controller:
public class ContextLessLogger(ILogger<ContextLessLogger> syslog)
{
public void Log()
{
StringBuilder viga = new();
viga.AppendLine("Line 1");
viga.AppendLine("Line 2");
syslog.Log(LogLevel.Warning, viga.ToString());
}
}
journalctl
shows Line 1 and Line 2 in single line:
veebr 12 22:33:52 myhost MyService[268922]: Eeva.Service.ContextLessLogger[0] Line 1 Line 2
Description in
https://learn.microsoft.com/en-us/dotnet/core/extensions/console-log-formatter
specifies that it always logs messages in a single line:
Systemd The ConsoleFormatterNames.Systemd console logger:
Uses the "Syslog" log level format and severities does not format
messages with colors Always logs messages in a single line
Describe the solution you'd like
Each li ne shoud appear as separate line in journal like other daemos do.
For example postgres creates multi line logs:
veebr 12 16:21:56 postgres[259580]: 2025-02-12 16:21:56 EET 1.2.3.3 stanislavs@sba ERROR: permission denied >
2025-02-12 16:21:56 EET 1.2.10.3 stanislavs@sba CONTEXT: unnamed portal w>
2025-02-12 16:21:56 EET 15.24.13.3 stanislavs@sba STATEMENT: update kasutaj>
where firmad='15' and kasutaja<>'LEAI' and $2 is distinct from 'Ja' >
journalctl output should be in two lines like in postgresql log:
veebr 12 22:33:52 myhost MyService[268922]: Eeva.Service.ContextLessLogger[0] Line 1
Line 2
Discussed in
https://stackoverflow.com/questions/79434420/how-to-write-multi-line-entry-to-linux-log
Additional context
No response