public static async void LogMessageToFile(string message, LoggingLevel level)
        {
            // Initialization
            if (fileLoggingSession == null)
            {
                fileLoggingSession = new FileLoggingSession("NewTestamentLogSession");
            }
            using (var loggingChannel = new LoggingChannel(
                       "NewTestamentLogSession",
                       new LoggingChannelOptions(new Guid("2e0582f3-d1b6-516a-00e3-9fd79ef95200")))) // Join a provider group
            {
                // The Id is generated by hashing the string "SampleProvider".
                // channel.Id == eff1e128-4903-5093-096a-bdc29b38456f
                fileLoggingSession.AddLoggingChannel(loggingChannel);
                // Log messages
                loggingChannel.LogMessage(message, level);
            }
            var file = await fileLoggingSession.CloseAndSaveToFileAsync();

            StorageFolder sampleAppDefinedLogFolder =
                await ApplicationData.Current.LocalFolder.CreateFolderAsync("Logs", CreationCollisionOption.OpenIfExists);

            string newLogFileName = "Log1-" + TimeStamp.Now() + ".etl";
            await file.MoveAsync(sampleAppDefinedLogFolder, newLogFileName);
        }
Example #2
0
        /// <summary>
        /// Closes the session save final log file.
        /// </summary>
        /// <returns>
        /// Final Log file name.
        /// </returns>
        private async Task <string> CloseSessionSaveFinalLogFile()
        {
            CheckDisposed();

            try
            {
                // Save the final log file before closing the this.localFileLogSession.
                StorageFile finalFileBeforeSuspend = await localFileLogSession.CloseAndSaveToFileAsync();

                if (finalFileBeforeSuspend != null)
                {
                    LogFileGeneratedCount++;

                    // Get the the app-defined log file folder.
                    StorageFolder sampleAppDefinedLogFolder =
                        await ApplicationData.Current.LocalFolder.CreateFolderAsync(
                            CommonConstants.LogAppLogFolderName,
                            CreationCollisionOption.OpenIfExists);

                    // Create a new log file name based on a date/time stamp.
                    string newLogFileName = string.Format(CultureInfo.CurrentCulture, "{0}-{1}.etl", CommonConstants.LogAppLogFileBaseName, GetTimeStamp());

                    // Move the final log into the app-defined log file folder.
                    await finalFileBeforeSuspend.MoveAsync(sampleAppDefinedLogFolder, newLogFileName);

                    // Return the path to the log folder.
                    return(System.IO.Path.Combine(sampleAppDefinedLogFolder.Path, newLogFileName));
                }
                else
                {
                    return(null);
                }
            }
            catch (ObjectDisposedException ex)
            {
                // TODO Clarify this
                DataStore.CN.NotifyException("Exception. ", ex);

                // The object is already disposed
                return(null);
            }
            catch (Exception ex)
            {
                DataStore.CN.NotifyException("CloseSessionSaveFinalLogFile", ex);

                throw;
            }
        }
Example #3
0
        private async Task <string> CloseSessionSaveFinalLogFile()
        {
            StorageFile finalFileBeforeSuspend = await session.CloseAndSaveToFileAsync();

            if (finalFileBeforeSuspend != null)
            {
                StorageFolder AppDefinedLogFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(APP_LOG_FILE_FOLDER_NAME, CreationCollisionOption.OpenIfExists);

                string newLogFileName = "Log-" + GetTimeStamp() + ".etl";
                await finalFileBeforeSuspend.MoveAsync(AppDefinedLogFolder, newLogFileName);

                return(System.IO.Path.Combine(AppDefinedLogFolder.Path, newLogFileName));
            }
            else
            {
                return(null);
            }
        }
Example #4
0
 public async Task CloseSession()
 {
     var storageFile = await Session.CloseAndSaveToFileAsync();
 }