Register logger in container (log4net) #2335
-
Hello, injection in the view model the output in text file is always pointing to App instead of the curent context which is in this case the viewModel can you please tell me how to register the logger and change the context each time a class call for it ? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Hello guys, and in each class we instanciate a new instance of the logger. |
Beta Was this translation helpful? Give feedback.
-
Other than the use of Open Generics, Prism's abstractions don't really have a way of handling the more complex factory that would be required to produce an instance of ILog with the name of the type that it is injected into. Not to say that it can't be done, but you will have to look to the underlying container for how to more appropriately handle this situation. As was already suggested you might try Unity.Log4Net if you are using Unity... If you're using DryIoc you may look to this sample from @dadhi on how to configure the container with Serilog. |
Beta Was this translation helpful? Give feedback.
-
I'll also add that you can always access the underlying container directly by using the |
Beta Was this translation helpful? Give feedback.
-
Hello,
now you are able to inject ILog in your view model : Thank you. |
Beta Was this translation helpful? Give feedback.
Other than the use of Open Generics, Prism's abstractions don't really have a way of handling the more complex factory that would be required to produce an instance of ILog with the name of the type that it is injected into. Not to say that it can't be done, but you will have to look to the underlying container for how to more appropriately handle this situation.
As was already suggested you might try Unity.Log4Net if you are using Unity... If you're using DryIoc you may look to this sample from @dadhi on how to configure the container with Serilog.
https://github.com/dadhi/DryIoc/blob/master/docs/DryIoc.Docs/ExamplesContextBasedResolution.md#serilog-logger