Пример #1
0
        private async Task SetupLogFileAsync()
        {
            if (string.IsNullOrWhiteSpace(this.LogPath))
            {
                string logFileName = string.Format(this.LogFileNameFormat, DateTime.Now);

                string logFileFolderPath = string.Empty;

#if WINDOWS_UWP || __ANDROID__ || __IOS__
                XPlat.Storage.IStorageFolder logsFolder =
                    await XPlat.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync(
                        this.LogsFolderName,
                        XPlat.Storage.CreationCollisionOption.OpenIfExists);

                XPlat.Storage.IStorageFile logFile = await logsFolder.CreateFileAsync(
                                                         logFileName,
                                                         XPlat.Storage.CreationCollisionOption.OpenIfExists);

                logFileFolderPath = logFile.Path;
#elif NETSTANDARD2_0
                string appFolderPath = AppDomain.CurrentDomain.BaseDirectory;
                string logsFolderPath = Path.Combine(appFolderPath, this.LogsFolderName);
#else
                string appFolderPath = AppContext.BaseDirectory;
                string logsFolderPath = Path.Combine(appFolderPath, this.LogsFolderName);
#endif

#if !(WINDOWS_UWP || __ANDROID__ || __IOS__)
                if (!string.IsNullOrWhiteSpace(logsFolderPath))
                {
                    if (!Directory.Exists(logsFolderPath))
                    {
                        Directory.CreateDirectory(logsFolderPath);
                    }

                    logFileFolderPath = Path.Combine(logsFolderPath, logFileName);
                    if (!File.Exists(logFileFolderPath))
                    {
                        File.Create(logFileFolderPath);
                    }
                }
#endif

                this.LogPath = logFileFolderPath;
            }

#if !(WINDOWS_UWP || __ANDROID__ || __IOS__)
            await Task.CompletedTask;
#endif
        }
Пример #2
0
        private async Task SetupLogFileAsync()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(this.LogPath))
                {
                    string logFileName = string.Format(this.LogFileNameFormat, DateTime.Now);

                    string logFileFolderPath = string.Empty;

#if WINDOWS_UWP || __ANDROID__ || __IOS__
                    XPlat.Storage.IStorageFolder logsFolder =
                        await XPlat.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync(
                            this.LogsFolderName,
                            XPlat.Storage.CreationCollisionOption.OpenIfExists);

                    XPlat.Storage.IStorageFile logFile = await logsFolder.CreateFileAsync(
                        logFileName,
                        XPlat.Storage.CreationCollisionOption.OpenIfExists);

                    logFileFolderPath = logFile.Path;
#elif NETSTANDARD2_0
                    string appFolderPath  = AppDomain.CurrentDomain.BaseDirectory;
                    string logsFolderPath = Path.Combine(appFolderPath, this.LogsFolderName);
#else
                    string appFolderPath  = AppContext.BaseDirectory;
                    string logsFolderPath = Path.Combine(appFolderPath, this.LogsFolderName);
#endif

#if !(WINDOWS_UWP || __ANDROID__ || __IOS__)
                    if (!string.IsNullOrWhiteSpace(logsFolderPath))
                    {
                        if (!Directory.Exists(logsFolderPath))
                        {
                            Directory.CreateDirectory(logsFolderPath);
                        }

                        logFileFolderPath = Path.Combine(logsFolderPath, logFileName);
                        if (!File.Exists(logFileFolderPath))
                        {
                            File.Create(logFileFolderPath);
                        }
                    }
#endif

                    this.LogPath = logFileFolderPath;
                }
            }
            catch (Exception ex)
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debug.WriteLine(
                        $"An exception was thrown while setting up the event log file. Error: {ex}");

                    throw;
                }
            }

#if !(WINDOWS_UWP || __ANDROID__ || __IOS__)
            await Task.CompletedTask;
#endif
        }