/// <summary> /// 在框架内执行实际的逻辑,框架将自动初始化日志和配置等功能 /// </summary> /// <param name="action"></param> /// <param name="entryAssembly"></param> /// <returns></returns> public static async Task <int> Run(Func <Task <int> > action, Assembly entryAssembly = null) { entryAssembly ??= Assembly.GetEntryAssembly(); // 预先设置框架内的日志输出,后续再次设置为项目配置的输出。开始是放在 Lazy 里面,因此基本不伤。框架内的调试输出是给 SDK 框架开发者了解的,上层业务开发者可以无须了解,因此框架的调试输出内容,不会输出给到上层业务开发者 Log.LogLevel = LogLevel.Information; var logger = Log.InitLazyLogger(); // 全局可以配置日志输出 var currentConfiguration = ConfigurationHelper.GetCurrentConfiguration(); var appConfigurator = currentConfiguration.CreateAppConfigurator(); Log.LogLevel = appConfigurator.Of <LogConfiguration>().LogLevel; AppConfigurator.SetAppConfigurator(appConfigurator); LogApplicationInfo(entryAssembly); SetCommonConfiguration(appConfigurator); // 完成框架,重新设置一下日志 logger.SwitchActualLogger(); try { return(await action()); } finally { // 清空日志缓存 logger.LogCacheMessage(); if (currentConfiguration is FileConfigurationRepo fileConfiguration) { await fileConfiguration.SaveAsync(); } } }