public static string InitLogDir(string?alias = null) { var logDirPath = Path.Combine(AppContext.BaseDirectory, "Logs"); IOPath.DirCreateByNotExists(logDirPath); #if StartupTrace StartupTrace.Restart("InitLogDir.IO"); #endif var logDirPath_ = logDirPath + Path.DirectorySeparatorChar; InternalLogger.LogFile = logDirPath_ + "internal-nlog" + alias + ".txt"; InternalLogger.LogLevel = NLogLevel.Error; var objConfig = new LoggingConfiguration(); var logfile = new FileTarget("logfile") { FileName = logDirPath_ + "nlog-all-${shortdate}" + alias + ".log", Layout = "${longdate}|${level}|${logger}|${message} |${all-event-properties} ${exception:format=tostring}", }; objConfig.AddTarget(logfile); objConfig.AddRule(NLogLevel.Error, NLogLevel.Fatal, logfile, "Microsoft.*"); objConfig.AddRule(NLogLevel.Error, NLogLevel.Fatal, logfile, "System.Net.Http.*"); objConfig.AddRule(AppHelper.DefaultNLoggerMinLevel, NLogLevel.Fatal, logfile, "*"); #if StartupTrace StartupTrace.Restart("InitLogDir.CreateLoggingConfiguration"); #endif LogManager.Configuration = objConfig; return(logDirPath); }
/// <summary> /// 初始化文件系统 /// </summary> public static void InitFileSystem() { //var appDataRootPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); //if (string.IsNullOrWhiteSpace(appDataRootPath)) //{ // // 需要测试 macOS 和 linux 上 Environment.SpecialFolder.ApplicationData 返回的目录值 // // 之前在 android 上测试过 Environment.GetFolderPath 有些枚举值返回的是空字符串 比如StartMenu // throw new ArgumentNullException(nameof(appDataRootPath)); //} //appDataRootPath = Path.Combine(appDataRootPath, BuildConfig.APPLICATION_ID); var appDataRootPath = #if NET35 WinFormsApplication.StartupPath; #else AppContext.BaseDirectory; #endif var appDataPath = Path.Combine(appDataRootPath, AppDataDirName); var cachePath = Path.Combine(appDataRootPath, CacheDirName); IOPath.DirCreateByNotExists(appDataPath); IOPath.DirCreateByNotExists(cachePath); IOPath.InitFileSystem(GetAppDataDirectory, GetCacheDirectory); string GetAppDataDirectory() => appDataPath; string GetCacheDirectory() => cachePath; }
static SQLiteAsyncConnection GetConnection() { var dbPath = DataBaseDirectory; IOPath.DirCreateByNotExists(dbPath); dbPath = Path.Combine(dbPath, "application.dbf"); return(new SQLiteAsyncConnection(dbPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.SharedCache)); }
public static void InitFileSystemByBaseDirectory() { var appDataPath = BaseDirectory.AppDataDirectory; var cachePath = BaseDirectory.CacheDirectory; IOPath.DirCreateByNotExists(appDataPath); IOPath.DirCreateByNotExists(cachePath); InitFileSystem(GetAppDataDirectory, GetCacheDirectory); string GetAppDataDirectory() => appDataPath; string GetCacheDirectory() => cachePath; }
/// <inheritdoc cref="FileSystem2.InitFileSystem"/> public static void InitFileSystem() { // https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/FileSystem/FileSystem.ios.tvos.watchos.macos.cs var appDataPath = Path.Combine(GetDirectory(NSSearchPathDirectory.LibraryDirectory), Constants.HARDCODED_APP_NAME); var cachePath = Path.Combine(GetDirectory(NSSearchPathDirectory.CachesDirectory), Constants.HARDCODED_APP_NAME); IOPath.DirCreateByNotExists(appDataPath); IOPath.DirCreateByNotExists(cachePath); InitFileSystem(GetAppDataDirectory, GetCacheDirectory); string GetAppDataDirectory() => appDataPath; string GetCacheDirectory() => cachePath; }
/// <summary> /// 获取文件夹路径,返回的路径必定存在 /// </summary> /// <param name="folder"></param> /// <returns></returns> public static string GetPath(this AppFolder folder) { var path1 = folder switch { AppFolder.Images or AppFolder.Cache => IOPath.CacheDirectory, AppFolder.Database => IOPath.AppDataDirectory, _ => throw new ArgumentOutOfRangeException(nameof(folder), folder, null), }; var path = Path.Combine(path1, folder.ToString()); IOPath.DirCreateByNotExists(path); return(path); }
/// <summary> /// 初始化文件系统 /// </summary> public static void InitFileSystem() { var path = AppContext.BaseDirectory; var path1 = Path.Combine(path, "AppData"); IOPath.DirCreateByNotExists(path1); var path2 = Path.Combine(path, "Cache"); IOPath.DirCreateByNotExists(path2); string GetAppDataDirectory() => path1; string GetCacheDirectory() => path2; InitFileSystem(GetAppDataDirectory, GetCacheDirectory); }
public void OneTimeSetUp() { // TODO: Add code here that is run before // all tests in the assembly are run if (!DIInit) { ModelValidatorProvider.Init(); DI.Init(ConfigureServices); var path = AppContext.BaseDirectory; var path1 = Path.Combine(path, "AppData"); IOPath.DirCreateByNotExists(path1); var path2 = Path.Combine(path, "Cache"); IOPath.DirCreateByNotExists(path2); string GetAppDataDirectory() => path1; string GetCacheDirectory() => path2; IOPath.InitFileSystem(GetAppDataDirectory, GetCacheDirectory); } }