I am using Azure Functions in Isolated mode, .NET 7.
I am able to inject a logger into my functions pretty easily by simpler adding an ILogger to the constructor of my functions and having the logging config setup in host.json file.
I can also inject an ILogger to any class, if I make that class an Interface, and inject the interface in my startup method.
However, I find this cumbersome, as often I don't need an interface, so I am making an Interface just for a single class to implement it, and sometimes I want to instantiate my object with property values, and then the DI won't work in those cases.
Is there a simple way/design pattern that allows me to have a single static or Singleton method Logger.Log("Message") from anywhere in my entire solution?
Aucun commentaire:
Enregistrer un commentaire