public async Task Log(Exception exception)
        {
            try
            {
                if (logSession != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(string.Format("Error Message: {0}", exception.Message));
                    sb.AppendLine(string.Format("UnhandledError: 0x{0:X})", exception.HResult));
                    sb.AppendLine(string.Format("Stacktrace: {0}", exception?.StackTrace ?? string.Empty));

                    logChannel.LogMessage(sb.ToString(), LoggingLevel.Critical);

                    await semaphoreLock.WaitAsync();

                    try
                    {
                        await logSession.SaveToFileAsync(logFolder, fileName);
                    }
                    finally
                    {
                        semaphoreLock.Release();
                    }
                }
            }
            catch { }
        }
Exemple #2
0
        /// <summary>
        /// Invoked when Navigation to a certain page fails
        /// </summary>
        /// <param name="sender">The Frame which failed navigation</param>
        /// <param name="e">Details about the navigation failure</param>
        async void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            var message = string.Format("Failed to navigate to page: {0}", e.SourcePageType.FullName);

            LogEventSource.Log.Critical(message);
            channel.LogMessage(message, LoggingLevel.Critical);
            var file =
                await session.SaveToFileAsync(ApplicationData.Current.TemporaryFolder, "log_" + DateTime.Now.Ticks);

            throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
        }
Exemple #3
0
        public async Task <StorageFile> SaveLogToFileAsync(string prefix = null)
        {
            if (_session == null || _channel == null)
            {
                Debug.WriteLine("Error: Logger is not initialized");
                return(null);
            }

            var fileName = prefix + "_" + DateTime.UtcNow.ToString("yyyy-MM-ddTHHmmss") + ".etl";

            var logFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(LogFolderName, CreationCollisionOption.OpenIfExists);

            return(await _session.SaveToFileAsync(logFolder, fileName));
        }
Exemple #4
0
        private StorageFile SaveFile()
        {
            if (LoggingSession == null)
            {
                return(null);
            }

            var task = LoggingSession
                       .SaveToFileAsync(LoggingFolder, $"{DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss-tt")}.{BaseName}.etl")
                       .AsTask();

            task.Wait();

            return(task.Result);
        }
        private static async Task <string> SaveLogInMemoryToFileAsync()
        {
            StorageFolder sampleAppDefinedLogFolder =
                await ApplicationData.Current.LocalFolder.CreateFolderAsync(LOG_FILE_FOLDER_NAME,
                                                                            CreationCollisionOption.OpenIfExists);

            string      newLogFileName = "Log-" + GetTimeStamp() + ".etl";
            StorageFile newLogFile     = await _Session.SaveToFileAsync(sampleAppDefinedLogFolder, newLogFileName);

            if (newLogFile != null)
            {
                return(newLogFile.Path);
            }
            else
            {
                return(null);
            }
        }