Registration using contextual information

I am working on a greenfield project and I want to integrate serilog with ninject.

The use case looks like this:

  • There are several shared libraries
  • These libraries are used in several modules ie plugins. These plugins each receive a GUID at runtime, which is unique. This is a base property in the abstract plugin class that every plugin implementation inherits
  • We want to add this unique name to every log message that the plugin makes, as well as any calls to shared libraries from that plugin, so that the log message can be traced back to the unique instance of the plugin that did it.
    • We would prefer not to modify every class in shared libraries to use a logger for use in the log

My thoughts were as follows:

  • Create a single registrar provider. This will be triggered by whatever it takes to register.
    • Use postsharp and CallContext.LogicalSetData to set the GUID before any call to the protocol provider
    • Use CallContext.LogicalGetData to get the GUID in a single log provider. This will either retrieve the existing logger for that GUID using Logger.ContextFor, or create a new one to add to the dictionary.
    • Use Ninject to resolve ILoggerProvider to singleton provider always on request

Before I go to this circular route, is there a better way to do it, maybe with ninject?

Thanks for reading.

+3


source to share


1 answer


I went with the solution as described, but due to the fact that it was single, there was no need for ninject in the end.



The solution works and does not seem to have performance issues on high volumes

0


source







All Articles