Пример #1
0
        /// <summary>
        ///
        /// </summary>
        protected void Application_Start()
        {
            //log4net
            var fileInfo = new FileInfo(Config.Root + "/Log4net.config");

            log4net.Config.XmlConfigurator.Configure(fileInfo);

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            HttpFilterConfig.RegisterGlobalFilters(GlobalConfiguration.Configuration.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            var settings = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;

            settings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
            settings.Culture = new CultureInfo("zh-CN");

            // json
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

            //
            $"{Config.Root}/Files/Temp/".CreateDir();
            $"{Config.Root}/Logs/".CreateDir();

            //只读权限
            DirectoryHelper.AddDirectoryReadAuth($"{Config.Root}/Files");

            //清理日志
            CreanFileHelper.Start(new CreanFileParam()
            {
                FileTimes = new List <FileTime>()
                {
                    new FileTime()
                    {
                        DeleteTime  = TimeSpan.FromDays(30),
                        Directories = new List <string>()
                        {
                            $"{AppDomain.CurrentDomain.BaseDirectory}Logs"
                        }
                    },
                    new FileTime()
                    {
                        DeleteTime  = TimeSpan.FromDays(1),
                        Directories = new List <string>()
                        {
                            $"{AppDomain.CurrentDomain.BaseDirectory}Files/Temp"
                        }
                    },
                },
                Log     = ex => LogHelper.Fatal(ex.Message, ex),
                DueTime = TimeSpan.FromMinutes(1),
                Period  = TimeSpan.FromHours(6)
            });
        }
Пример #2
0
        public void TestMethod9()
        {
            var dir = $"{TestConfig.BinDir}Files/config/";

            dir.CreateDir();

            DirectoryHelper.AddDirectoryReadAuth(dir);

            var path = $"{dir}web.config";

            Assert.IsTrue(File.Exists(path));

            //删除文件
            FileHelper.DeleteFile(path, false);
        }