Ejemplo n.º 1
0
        private static void Initialize()
        {
            Log4NetLoggerAdapter adapter = new Log4NetLoggerAdapter();

            LogManager.AddLoggerAdapter(adapter);

            ICacheProvider provider = new RuntimeMemoryCacheProvider();

            CacheManager.SetProvider(provider, CacheLevel.First);

            IServicesBuilder builder = new ServicesBuilder();

            try
            {
                IServiceCollection services = builder.Build();

                services.AddLog4NetServices();
                services.AddDataServices();
                services.AddImplementServices();
                services.AddMdSmsServices();
                //services.AddJPushServices();


                IFrameworkInitializer initializer = new FrameworkInitializer();
                initializer.Initialize(new MvcAutofacIocBuilder(services));
                initializer.Initialize(new WebApiAutofacIocBuilder(services));
                //initializer.Initialize(new SignalRAutofacIocBuilder(services));
            }

            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Application Started ...");

            _log4NetLoggerAdapter = new Log4NetLoggerAdapter();

            // Debug
            var logEntry = new LogEntry(typeof(Program), LoggingEventType.Debug, $"Debug Message");

            _log4NetLoggerAdapter.Log(logEntry);

            // Debug : IgnoreFilter
            logEntry = new LogEntry(typeof(Program), LoggingEventType.Debug, $"Will be ignored because of DebugIgnoreFilter");
            _log4NetLoggerAdapter.Log(logEntry);

            // Info
            logEntry = new LogEntry(typeof(Program), LoggingEventType.Information, $"Info");
            _log4NetLoggerAdapter.Log(logEntry);

            // Warn
            logEntry = new LogEntry(typeof(Program), LoggingEventType.Warning, $"Warning !!");
            _log4NetLoggerAdapter.Log(logEntry);

            // Error
            logEntry = new LogEntry(typeof(Program), LoggingEventType.Error, $"Error Occured ");
            _log4NetLoggerAdapter.Log(logEntry);

            // Fatal
            logEntry = new LogEntry(typeof(Program), LoggingEventType.Fatal, $"Exception thrown", new ApplicationException("An exception occured"));
            _log4NetLoggerAdapter.Log(logEntry);

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        ///// <summary>
        ///// 加载应用程序集
        ///// </summary>
        ///// <param name="folder"></param>
        //public override void LoadAssemblies()
        //{
        //    if (PlusAssemblysList == null)
        //        PlusAssemblysList = new List<PluginDescriptor>();
        //    else
        //        PlusAssemblysList.Clear();

        //    #region 插件文件目录
        //    var plusFilesDirectoryInfo = new DirectoryInfo(SitePaths.PlusFilesDirPath);
        //    #endregion
        //    //插件前缀必须为Innocellence
        //    var plusDlls = plusFilesDirectoryInfo.GetFiles("*.dll", SearchOption.AllDirectories).ToList();
        //    if (plusDlls.Count == 0) return;
        //    //插件程序集
        //    //必须是Innocellence插件才会执行插件部署
        //    //dll名称必须与插件目录名称一致才能部署
        //    //{PlusDir}/{dllName}
        //    //{PlusDir}/bin/{dllName}
        //    var magicodesPlusDlls = plusDlls.Where(p => p.Name.StartsWith("Innocellence.") && (p.Directory.Name + ".dll" == p.Name || p.Directory.Parent.Name + ".dll" == p.Name));
        //    //依赖的程序集
        //    var orthersDlls = plusDlls.Where(p => !p.Name.StartsWith("Innocellence.")).Distinct();
        //    #region 设置程序域
        //    //var setup = new AppDomainSetup
        //    //{
        //    //    ApplicationName = "Infrastructure.Core",
        //    //    //DynamicBase = SitePaths.PlusShadowCopyDirPath,
        //    //    PrivateBinPath = SitePaths.PlusShadowCopyDirPath,
        //    //    DisallowCodeDownload = true,
        //    //    ShadowCopyFiles = "true",
        //    //    CachePath = SitePaths.PlusCacheDirPath,
        //    //    ShadowCopyDirectories = SitePaths.PlusShadowCopyDirPath,
        //    //    //PrivateBinPath = SitePaths.PlusShadowCopyDirPath
        //    //};
        //    //var appDomain = AppDomain.CreateDomain("Infrastructure.Core.Domain", null, setup);
        //    CurrentAppDomain = AppDomain.CurrentDomain;
        //    if (!CurrentAppDomain.IsFullyTrusted)
        //        throw new InnocellenceException("请将当前应用程序信任级别设置为完全信任");

        //    #endregion
        //    var binDir = new DirectoryInfo(SitePaths.SiteRootBinDirPath);

        //    #region 部署依赖程序集
        //    foreach (var plus in orthersDlls)
        //    {
        //        //如果网站bin目录不存在此dll,则将该dll复制到动态程序集目录
        //        if (binDir.GetFiles(plus.Name).Length == 0 && PluginManager.DynamicDirectory.GetFiles(plus.Name).Length == 0)
        //        {
        //            _PluginManager.CopyToDynamicDirectory(plus);
        //            Assembly assembly = Assembly.LoadFrom(plus.FullName);
        //            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
        //            if (!assemblies.Any(p => p.FullName == assembly.FullName))
        //                //将程序集添加到当前应用程序域
        //                BuildManager.AddReferencedAssembly(assembly);
        //        }

        //    }
        //    #endregion
        //    #region 部署插件程序集
        //    foreach (var plus in magicodesPlusDlls)
        //    {
        //        PluginManager.Deploy(plus);
        //    }
        //    #endregion
        //    #region 添加插件菜单
        //    var siteAdminNavigationRepository = APIContext<string>.Current.SiteAdminNavigationRepository;
        //    if (siteAdminNavigationRepository == null) return;
        //    #region 移除所有的插件菜单
        //    if (siteAdminNavigationRepository.GetQueryable().Any())
        //    {
        //        siteAdminNavigationRepository.RemoveRange(siteAdminNavigationRepository.GetQueryable());
        //        siteAdminNavigationRepository.SaveChanges();
        //    }
        //    #endregion
        //    //foreach (var plusInfo in PluginManager.ReferencedPlugins)
        //    //{
        //    //    if (plusInfo.PlusConfigInfo != null && plusInfo.PlusConfigInfo.PlusMenus != null && plusInfo.PlusConfigInfo.PlusMenus.Length > 0)
        //    //    {
        //    //        foreach (var plusMenu in plusInfo.PlusConfigInfo.PlusMenus)
        //    //        {
        //    //            AddPlusMenu(plusInfo, siteAdminNavigationRepository, plusMenu, null);
        //    //        }
        //    //    }
        //    //}
        //    siteAdminNavigationRepository.SaveChanges();
        //    #endregion
        //}
        ///// <summary>
        ///// 添加菜单
        ///// </summary>
        ///// <param name="plusInfo"></param>
        ///// <param name="r"></param>
        ///// <param name="plusMenu"></param>
        ///// <param name="parentId"></param>
        //private static void AddPlusMenu(PluginDescriptor plusInfo, SiteAdminNavigationRepositoryBase<string> r, PlusMenu plusMenu, Guid? parentId)
        //{
        //    var nav = new SiteAdminNavigationBase<string>()
        //    {
        //        BadgeRequestUrl = plusMenu.BadgeRequestUrl,
        //        Href = plusMenu.Href,
        //        IconCls = plusMenu.IconCls,
        //        Id = plusMenu.Id ?? Guid.NewGuid(),
        //        IsShowBadge = plusMenu.IsShowBadge,
        //        MenuBadgeType = plusMenu.MenuBadgeType,
        //        ParentId = plusMenu.ParentId ?? parentId,
        //        Text = plusMenu.Text,
        //        TextCls = plusMenu.TextCls,
        //        Deleted = false,
        //        //TODO:设置管理员账号
        //        CreateBy = "{B0FBB2AC-3174-4E5A-B772-98CF776BD4B9}",
        //        CreateTime = DateTime.Now,
        //        PlusId = plusInfo.Id
        //    };
        //    r.Add(nav);
        //    if (plusMenu.SubMenus != null && plusMenu.SubMenus.Length > 0)
        //    {
        //        foreach (var item in plusMenu.SubMenus)
        //        {
        //            AddPlusMenu(plusInfo, r, item, nav.Id);
        //        }
        //    }
        //}


        /// <summary>
        /// 应用程序日志类
        /// </summary>
        //public override LoggerStrategyBase ApplicationLog
        //{
        //    get
        //    {
        //        return this.StrategyManager.GetDefaultStrategy<LoggerStrategyBase>();
        //    }
        //}

        public override void PreApplicationStartInitialize()
        {
            //初始化策略管理器
            // StrategyManager = new StrategyManager();
            //初始化插件管理器
            //_PluginManager = new PluginManager();
            //【优先加载框架策略】加载框架策略作为默认策略,如果插件实现了该策略,则会被覆盖
            //默认集成了日志策略
            // _PluginManager.LoadPlusStrategys(this.GetType().Assembly);
            //初始化嵌入资源管理器
            //ManifestResourceManager = new ManifestResourceManager();
            //初始化文档协议管理器
            //   DocumentsOpenProtocolManager = new DocumentsOpenProtocolManager();


            log4net.Config.XmlConfigurator.Configure(new FileInfo(HostingEnvironment.MapPath("~/config/log4net.config")));

            Log4NetLoggerAdapter adapter = new Log4NetLoggerAdapter();

            LogManager.AddLoggerAdapter(adapter);

            //初始化配置管理器
            ConfigManager = new ConfigManager();
            //加载程序集
            // LoadAssemblies();

            //初始化Plugin
            PluginManager.Initialize();

            //初始化系统
            EngineContext.Initialize(false);

            //初始化数据库
            DatabaseInitialize();



            GlobalConfigurationManager.MapHttpAttributeRoutes();
            //初始化OData
            GlobalConfigurationManager.InitializeODATA();
            //初始化WebApi
            GlobalConfigurationManager.InitializeWebAPI();
            //初始化MVC插件引擎
            GlobalConfigurationManager.InitializeMVCEngines();


            //执行plugin的install方法
            //PluginManager.ExcuteAllInstallEvent();
        }
Ejemplo n.º 4
0
        private static void LoggingInitialize()
        {
            Log4NetLoggerAdapter adapter = new Log4NetLoggerAdapter();

            LogManager.AddLoggerAdapter(adapter);
        }