This project is read-only.

Question regarding constructor injection

Nov 6, 2014 at 11:17 AM
I am using simple injector for a larger project. I do however have a small "challenge" (I would not call it a problem) I hope your guys could help with.

We are using serilog as logging framework and I am currently injecting ILogger instances through the constructor.

I would however like to make sure all log-events include the name of the class from which the log-event have been triggered. Luckily this can be partly automated by using serilogs GetLog.ForContext method. Here is an example:
var myLog = Log.ForContext<MyClass>();
So now for my Simple injector related question. Is there any way I can configure simple.injector to invoke LogForContext and return the resulting ILogger every time a class requests an instance of the ILogger?

I really hope the question make sense. I wasn't really sure how to explain it. Thank you very much in advance and have a nice day!

Regards Kenneth
Nov 6, 2014 at 12:10 PM
Hi Kenneth,

What you need is explained here in the documentation. And don't forget to read this.