3

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

The use case is as follows:

  • There are a number of common libraries
  • These libraries are used in a number of modules i.e plugins. These plugins each receive a GUID at run time which is unique. This is a base property on an abstract plugin class which every implementation of a plugin inherits
  • We want to append this unique name to every log message that a plugin makes as well as any calls to the common libraries from that plugin so that a log message can be traced to the unique instance of a plugin that made it
    • We would prefer not to modify each class in the common libraries to take in a logger to use to log

My thoughts were to :

  • Create a singleton logger provider. This will be called by anything needing to log.
    • Use postsharp and CallContext.LogicalSetData to set the GUID prior to any call to the logging provider
    • Use CallContext.LogicalGetData to get the GUID in the singleton logger provider. This will either retrieve an existing logger for that GUID using Logger.ContextFor or create a new one to add to a dictionary.
    • Use Ninject to resolve the ILoggerProvider to the singleton provider always when requested

Before I down this circuitious route, is there a better way to do this, maybe with ninject?

Thanks for reading.

Bernard
  • 995
  • 2
  • 9
  • 20

1 Answers1

0

I went with the solution as described but due to it being a singleton there was no need for ninject in the end.

The solution is working and doesnt seem to have any performance issues logging at high volumes

Bernard
  • 995
  • 2
  • 9
  • 20