Like Collectionordermodule, Loggingmodule is also a AUTOFAC module. It sets the logger for the object that needs the log service in the form of an attribute injection.
If a class has a public writable instance property of type Orchard.Logging.ILogger (ignoring the index), the AUTOFAC container will "inject" an instance of a Ilogging implementation class when parsing (Resolve) the class. Orchard a Castlelogger object is injected by default. Of course Orchard also allows multiple ILogger properties in a class, and also supports replacing castlelogger with other logger.
if necessary, check out the simple Factory mode, abstract Factory mode, and adapter mode first. The Castleloggerfactory factory is responsible for creating Castlelogger objects, and castleloggerfactory is suitable for Orchardlog4netfactory;castlelogger actually adapting The Orchardlog4netlogger;orchardlog4netlogger is also suitable for a log4net. core.ilogger--that is to say Castlelogger is the result of Log4net.Core.ILogger after layer packing . If there is a class Testcontrller, which has a ilogger-type attribute named logger, the injection process is as follows: 1, AUTOFAC container to create an instance of TestController class instance; 2. Check if instance has a public writable instance property of type ILogger. If there is (possibly more than one) then go to step 3, otherwise the following steps are not necessary; 3, obtain the TestController type corresponding logger from the cache, if obtain successfully enters step 6; 4. Get ILogger from AUTOFAC container:get castleloggerfactory from the container->castleloggerfactory creating ILogger objectsby orchardlog4netfactory Create Orchardlog4netloggerby Log4net. Logmanager.getlogger creating a Log4net.Core.ILogger object->log4net. Core.ilogger objects Fit into Orchardlog4netlogger objects->orchardlog4netlogger objects Fit into Castlelogger objects->castleloggerfactory eventually returns a Castlelogger object5. Cache Castlelogger objects (associated with the TestController Class)6. Inject Castlelogger into the logger property of the Testcontrller object. Related types:Orchard.Logging.CastleLogger:Orchard.Logging.ILoggerOrchard.Logging.CastleLoggerFactory:Orchard.Logging.ILoggerFactoryaOrchard.Logging.OrchardLog4netFactory: Castle.Core.Logging.ILoggerFactoryOrchard.Logging.OrchardLog4netLoggerCastle.Core.Logging.AbstractLoggerFactory
Resources:autofac:structuring with Modules autofac:activation eventsAUTOFAC: Attribute InjectionAutofac.moduleLog4netcastle Logging Simple Factory mode abstract Factory modeAdapter ModeHow Orchard CMS does the logging
Orchard Source Analysis (4.2): Orchard.Logging.LoggingModule class