-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
Pri3Indicates issues/PRs that are low priorityIndicates issues/PRs that are low priorityarea-Extensions-Logginghelp wantedGood for community contributors to help [up-for-grabs]Good for community contributors to help [up-for-grabs]untriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Description
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
Labels
Pri3Indicates issues/PRs that are low priorityIndicates issues/PRs that are low priorityarea-Extensions-Logginghelp wantedGood for community contributors to help [up-for-grabs]Good for community contributors to help [up-for-grabs]untriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
kjpgit commentedon Mar 24, 2022
The reason I figured it out: https://stackoverflow.com/questions/50221983/cant-get-console-logging-to-work-in-net-core-2-0
WeihanLi commentedon Mar 25, 2022
Think it's by design and maybe the issue should be transferred to dotnet/runtime
baronfel commentedon Mar 25, 2022
I'd agree with that: Environment.Exit per its docs doesn't wait for thread to finish:
kjpgit commentedon Mar 27, 2022
You can transfer the issue if it's appropriate. My question is, is it documented that the console logger buffers / delays the output? Is there a way to turn it off? What are the failure modes when the buffer grows?
ghost commentedon Apr 1, 2022
Tagging subscribers to this area: @dotnet/area-extensions-logging
See info in area-owners.md if you want to be subscribed.
Issue Details
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.
untriaged
,area-Extensions-Logging
,Area-NetSDK
maryamariyan commentedon Apr 27, 2022
That's by design. Keeping open and up for grabs in the dotnet-api-docs to track adding to docs.