Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No log entry when calling logger instance from Task #128

Closed
samirbanjanovic opened this issue Dec 7, 2018 · 1 comment
Closed

No log entry when calling logger instance from Task #128

samirbanjanovic opened this issue Dec 7, 2018 · 1 comment

Comments

@samirbanjanovic
Copy link

samirbanjanovic commented Dec 7, 2018

There could be a simple answer to this, and to be honest it seems to me to be context related. However, I figured I'd post here see if it get's a conversation started. In my scenario I have a class which hosts the LoggerFactory and is used to create a logger

        private readonly ILoggerFactory _loggerFactory;
        private readonly ILogger<MyClass> _logger;

        public MyClass()
        {            
            _loggerFactory = new LoggerFactory().AddSerilog(dispose: true);            
            _logger = _loggerFactory.CreateLogger<MyClass>();
        }

Logging works as expected as long as I am awaiting all my async methods or the method is synchronous. But, when I call _logger from a task I am not seeing those entries come through.

The code below yields now log entry:

        internal void Configure()
        {
            Task.Run(async () =>
            {
               // doing IO stuff
               
               //this log entry doesn't get committed
                _logger.LogInformation("{Message}", "Configuring services");

                SetComponentSettings();
                SetMessagePubslisherSettings();

                await SomeOtherStuffAsync();
            });
        }

I was able to get log entries to work by creating another logger within the Configure() method scope:
var scopedLogger = _loggerFactory.CreateLogger("ConfigurationLogger"); and calling scopedLogger from within the Task.

I am curious to what I am missing or if this is a legit issue

@nblumhardt
Copy link
Member

Nothing immediately comes to mind, @samirbanjanovic - I hope you found some clues somewhere. Closing as this issue is now a bit stale, but if you did end up tracking this down to something Serilog-related please let us know :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants