Multitenant LoggingLevelSwitch
We currently use DI container per tenant, and so can build an independent logging configuration per tenant with its own LoggingLevelSwitch - so we can adjust each tenant via its own switch. Having the tenants DI container swapped in at the start of each web request ensures that the tenants logging configuration, and thus switch, applies for the duration of the request.
However I am investigating simplifications, by centralising components, and making them multi-tenant aware. So rather than configure an instance per tenant DI container, you have a single instance of a component in the root application container, and its augmented to be "aware" of the current tenant contextually and behave accordingly.
So looking at LoggingLevelSwitch - is there a way to achieve this such that we can use
- a single logging configuration built at the start of the application
- tenants added dynamically at runtime
- a single "multi-tenant" log level switch - it returns the tenant log level based on current tenant context.
I was thinking perhaps its as simple as
- implementing my own LoggingLevelSwitch
- have it grab the minimum log level to return from current tenant context
- this could be in http context, or an async local etc.
Are there problems with this approach before I start down this road?
Source: serilog/serilog