Great video... How do you go about logging in a hosted service? I know you did a recent video about hosted services, just wondering how you can pass the logger to the hosted service.
Hi Cesar. Thanks for your comment. All you need to do is inject the ILogger type as a parameter into the Hosted Service constructor. You can then set its instance as a local variable within the Hosted Service and use the extension methods to log.
@@RoundTheCode thanks for the reply. I tried that but the ilogger in the constructor of the hosted service had a generic type of the hosted service class. So I ended up injecting an iloggerfactory and passing it as a parameter. Just got it working now. And from the iloggerfactory I can create a logger with the type of the current class. But thanks for the help.
Take a look at this StackOverflow thread and see if it answers your question: stackoverflow.com/questions/59173671/how-to-write-logs-to-eventlog-by-iloggert-in-asp-net-core