I am converting from Prism 2.1 to Prism 4, and I need to write an ILoggerFacade class for Log4Net. My old code from Prism 2.1 no longer works. Does anyone have sample code for an ILoggerFacade class they’d be willing to share? Thanks for your help.
Share
I figured it out. Very similar to Prism 2. First, create a custom logger class that implements ILoggerFacade. Here’s my class:
Then, in the Prism 4 Bootstrapper class, add an override to the
CreateLogger()method that returns a new instance of the custom logger class:Note that in the custom logger class,
ILogis a Log4Net interface, andLogManageris a Log4Net object.Writing to the custom logger from your own code (Prism takes care of its own log entries)is a little different than in Prism 2.1. You can resolve the logger directly from the IoC container, or you can use the ServiceLocator. The
ServiceLocatorhas the advantage of being container-agnostic, which means the underlying container doesn’t really matter. Here is an example of resolving a logger using the ServiceLocator:The
ServiceLocatorrequires that the host project have a reference to Microsoft.Practices.ServiceLocation.dll and a matchingusingstatement.