Skip to content

Console logging doesn't work unless there's a delay #7904

Open
@kjpgit

Description

@kjpgit
using System.Text;
using System.Diagnostics;

 using var loggerFactory = LoggerFactory.Create(builder =>
        {
            builder
                .AddFilter("Microsoft", LogLevel.Warning)
                .AddFilter("System", LogLevel.Warning)
                .AddConsole();
        });

ILogger logger = loggerFactory.CreateLogger<Program>();
logger.LogInformation("Example log message");

//await Task.Delay(100);

Environment.Exit(10);

The above does not print anything unless you uncomment the delay. I wasted an hour of time trying to figure out why logging wasn't working. A console does not buffer output. What happens if my process crashes and the last few log lines are lost?

For the record, I'm just making a .net console app that would be running as a systemd service, and systemd would capture the stdout. No reason to delay the output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-Extensions-Logginghelp wantedGood for community contributors to help [up-for-grabs]untriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions