How Orchard CMS does the logging?

后端 未结 2 2002
傲寒
傲寒 2021-02-14 20:10

I\'m working with Orchard CMS and it is better CMS for me. I want to understand how it does the logging and whether I can add my own logging or not. I saw that Orchard uses

2条回答
  •  感动是毒
    2021-02-14 20:43

    An Autofac module (Orchard.Logging.LoggerModule to be precise) handles that. Basically - it scans each dependency and fills all properties of type ILogger with a reference to appropriate logger instance. Each dependency gets its own logger with name equal to full type name (including namespace) of a containing class.

    The NullLogger is just a placeholder so accessing the property would not throw NullReferenceExceptions before the property is being set by Autofac.

    Extending the default logging is a rather complicated task as it would involve doing three things:

    • create a custom implementation of ILoggerFactory (just like the default Orchard.Logging.CastleLoggerFactory) and
    • create an Autofac module that registers that implementation in the container (like the mentioned LoggerModule does)
    • suppress the current default logging module by decorating your new one with [OrchardSuppressDependency("Orchard.Logging.LoggingModule")]

    UPDATE

    Just realized I haven't addressed the most important part of the question here:) Yes, Orchard uses log4net so you may alter the default settings via Config/log4net.config file.

提交回复
热议问题