Beispiel #1
0
        public static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                //.AddXmlFile("publicsetting.xml")
                                .AddEnvironmentVariables()
                                .AddCommandLine(args)
                                .Build();

            var       logConfig   = configuration.GetSection("Logging");
            int       maxDays     = 10;
            string    maxFileSize = "10MB";
            LogLevels logLevel    = LogLevels.Info;

            if (logConfig != null)
            {
                Enum.TryParse(logConfig["Level"] ?? "", out logLevel);
                int.TryParse(logConfig["SaveDays"], out maxDays);

                maxFileSize = logConfig["MaxFileSize"];
                if (string.IsNullOrEmpty(maxFileSize))
                {
                    maxFileSize = "10MB";
                }
            }
            LoggerManager.InitLogger(new LogConfig()
            {
                LogBaseDir         = logConfig["Path"],
                MaxFileSize        = maxFileSize,
                LogLevels          = logLevel,
                IsAsync            = true,
                LogFileTemplate    = LogFileTemplates.PerDayDirAndLogger,
                LogContentTemplate = LogLayoutTemplates.SimpleLayout,
                DeleteDay          = maxDays.ToString(),
                //TargetConsole = false
            });
            LoggerManager.SetLoggerAboveLevels(logLevel);

            ExceptionLogger = LoggerManager.GetLogger("Exception");

            //全局异常日志
            AppDomain.CurrentDomain.UnhandledException   += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;

            WebHost.CreateDefaultBuilder(args)
            .UseStartup <Startup>()
            .UseUrls($"http://*:{configuration["Port"]}")
            .Build()
            .Run();
        }
Beispiel #2
0
        public ApplicationContextImpl(IServiceCollection service)
            : base(service)
        {
            string pluginPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Plugin");

            if (!System.IO.Directory.Exists(pluginPath))
            {
                System.IO.Directory.CreateDirectory(pluginPath);
            }
            ExceptionLogger = LoggerManager.GetLogger("PluginInitException");

            //所有程序集
            DirectoryLoader dl      = new DirectoryLoader();
            List <Assembly> assList = new List <Assembly>();
            var             psl     = dl.LoadFromDirectory(pluginPath);

            assList.AddRange(psl);
            AdditionalAssembly = assList;
        }
Beispiel #3
0
        private static void CreateLogger(IHost host)
        {
            var logConfig = host.Services.GetRequiredService <IConfiguration>().GetSection("Logging");

            int       maxDays     = 10;
            string    maxFileSize = "10MB";
            LogLevels logLevel    = LogLevels.Info;

            if (logConfig != null)
            {
                _ = Enum.TryParse(logConfig["Level"] ?? "", out logLevel) &&
                    int.TryParse(logConfig["SaveDays"], out maxDays);

                maxFileSize = logConfig["MaxFileSize"];
                if (string.IsNullOrEmpty(maxFileSize))
                {
                    maxFileSize = "10MB";
                }
            }
            LoggerManager.InitLogger(new LogConfig()
            {
                LogBaseDir         = logConfig["Path"],
                MaxFileSize        = maxFileSize,
                LogLevels          = logLevel,
                IsAsync            = true,
                LogFileTemplate    = LogFileTemplates.PerDayDirAndLogger,
                LogContentTemplate = LogLayoutTemplates.SimpleLayout,
                DeleteDay          = maxDays.ToString(CultureInfo.CurrentCulture),
#if DEBUG
#else
                TargetConsole = true
#endif
            });
            LoggerManager.SetLoggerAboveLevels(logLevel);

            ExceptionLogger = LoggerManager.GetLogger("Exception");
            StartLogger     = LoggerManager.GetLogger("Main");
        }