C
C#5mo ago
Kydd

Use different Logging provider depending on the context

In my .NET 7 web-app, I want to send some logs to different Logging Providers depending on the User of the request. It seems that this should be doable, but I am not sure how to set this up. Should I enable all loggers, and then use filters? Or should I inject user-specific logger in the DI? For instance, When a User A does a request to my app, it will log to Console Logger and Serilog. If a User B makes a request, it will log to Sentry and Serilog (with a different configuration). How can I achieve this?
1 Reply
Pobiega
Pobiega5mo ago
I'd probably use serilog as my entrypoint with multiple sinks, and expose the property that is used to decide if Sentry should be logged to or not as part of the log event. Then you just have a sink filter look for that property on the Sentry sink