日志模块的结构图如下:
日志模块通过继承Load函数,实现日志工厂Log4netLoggerFactory的注册和Logger的注入,最终只有在调用的类里实现
public ILogger Logger { get; set; }
就能输出日志。
// 2020-11-17 by www.cnblogs.com/ztcad namespace ztcad.Cad.Framework.Services { public class ModelSpaceService : IModelSpaceService { private readonly ICommonServices _services; private readonly IBlockService _blockService; public ModelSpaceService( ICommonServices services, IBlockService blockService) { _services = services; _blockService = blockService; Logger = NullLogger.Instance; } public ILogger Logger { get; set; } public virtual void InsertBlockReference(string name, Point3d position) { Block block = _blockService.GetBlock(name); if (block == null) { Logger.Debug(string.Format("块'{0}'不存在! ", name)); return; } } } }