❔ Log from helper class without creating new context? (Serilog)
I have a bunch of services with their own dedicated loggers that have config'd settings for filtering based on that exact type:
This way, I can setup output log files for each service individually.
Now I have a helper class that all of the services utilize, and I want to add logging to this helper class, but I want the logs to appear in the log file that the calling service already has going. Since the filtering above is based on type, I'm not sure how to wire this up.
Right now my helper class is setup to use DI like:
But this seems to create a new logger for
Helper
specifically, which isn't caught by the calling service's logger filtering.4 Replies
Seems like you should di 'your logger<T>' into the classes instead of logger<T>. Unless you can modify the logger factory somehow
i don't follow. my entrypoint DI is setup like this
and each service and helper has the standard
ILogger<T>
ctor parameter, where T is that service/class nameMaybe simplest to just provide method overloads that take an Ilogger, and pass the logger in from your other services
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.