How to mole SharePointServiceLocator to work with the logger

111 Views Asked by At

I trying to figure out how to mole the

Microsoft.Practices.SharePoint.Common.ServiceLocation.SharePointServiceLocator.GetCurrentFarmLocator

because I trying to use

 Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace

some help or example?

1

There are 1 best solutions below

0
On

I found a solution by myself using the SharePointServiceLocator. Basically I implemented this on my code:

            var replaceLocator = new ActivatingServiceLocator ( );
            SharePointServiceLocator.ReplaceCurrentServiceLocator ( replaceLocator );
            replaceLocator.RegisterTypeMapping < ILogger, MockLogger > ( InstantiationType.AsSingleton );
            replaceLocator.RegisterTypeMapping < ITraceLogger, MockLogger > ( InstantiationType.AsSingleton );
            replaceLocator.RegisterTypeMapping < IEventLogLogger, MockLogger > ( InstantiationType.AsSingleton );