-
Notifications
You must be signed in to change notification settings - Fork 251
Console logger from DI doesn't produce console output #631
Comments
After a short investigation, it seems like logging a couple times wont output, but more logs causes the output to be flushed. Looking to see if CoreFX made any changes in the area recently. |
So this is because we do console logging on a background thread. So if the application exits too fast then the logger doesn't have time to log. |
We'll investigate further. |
This should be fixed if you dispose service provider before exiting |
Yes, disposing flushes the message queue. Could we also add a ProcessExit event to flush the queue, in the event the service provider isn't disposed correctly? |
Does it work well crossplat? |
This API is in ns2.0: |
Is this still a problem? |
Depends if we count not disposing logging provider as a valid usage. I it not worth to overcomplicate logger code to fix invalid usage. |
At least it stole some hour or so from me trying to understand why my simple test didn't produce any result, and quite frankly, I was surprised how immature this story seem. Having a multi-targeting app ( void Main() {
var factory = new LoggerFactory().AddConsole(LogLevel.Trace);
var logger = factory.CreateLogger("Test");
logger.LogTrace("Hello!");
} Running with simply Even logging 100 of those showed nothing (as someone suggested could be an idea). Not until I yielded the main thread (doing Edit: used these references:
|
Any update on fixing this? Just tried in mstest, in any short test all the logs are lost and never captured. I have not services to dispose in the unit test, please fix or give me a flush method. |
Okay I was able to dispose of the ConsoleLoggerProvider to force a flush in my unit test, wish I could configure this background thread thing off for tests. Also seems like disposing of LoggerFactory should also dispose of any connected loggers but it does not. |
@AceHack I would think for unit testing you could add your own test logging provider, no need to tie in with the console logger. |
Are you sure? There is a test that checks exactly that https://github.com/aspnet/Logging/blob/dev/test/Microsoft.Extensions.Logging.Test/LoggerFactoryTest.cs#L46 |
* Fixes #18, https://github.com/RetireNet/dotnet-retire/issue/18 * Fixes the issue with loglevel=error not working * Reference: aspnet/Logging#631
* Fixes #18, https://github.com/RetireNet/dotnet-retire/issue/18 * Fixes the issue with loglevel=error not working * Reference: aspnet/Logging#631
When IDisposable objects are disposed things are working correctly. No plans to improve anything in this area. |
Console logger does not produce output when using 2.0.0-preview3-25445.
cc @pakrym @BrennanConroy
The text was updated successfully, but these errors were encountered: