Windows Dev Center

FileLoggingSession class

Represents the destination of logged messages from LoggingChannel instances.


var fileLoggingSession = new Windows.Foundation.Diagnostics.FileLoggingSession();


The FileLoggingSession class has these types of members:


The FileLoggingSession class has these constructors.

FileLoggingSession Initializes a new instance of the FileLoggingSession class.



The FileLoggingSession class has these events.

LogFileGenerated Raised when a log file is saved.



The FileLoggingSession class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

AddLoggingChannel(ILoggingChannel) Adds a logging channel to the current logging session.
AddLoggingChannel(ILoggingChannel, LoggingLevel) Adds a logging channel to the current logging session. The logging channel only accepts events that have a logging level at or above the specified logging level.
Close [C++, JavaScript]Ends the current logging session.
CloseAndSaveToFileAsync Ends the current logging session and saves it to a file.
Dispose [C#, VB]Performs tasks associated with freeing, releasing, or resetting unmanaged resources.
RemoveLoggingChannel Removes the specified logging channel from the current logging session.



The FileLoggingSession class has these properties.

PropertyAccess typeDescription


Read-onlyGets the name of the logging session.



Use the FileLoggingSession class to log messages and data to a file continuously as your app runs. You can view the log files by using the Windows Performance Toolkit (WPT) and other utilities like tracerpt.exe.

Add LoggingChannel instances to a FileLoggingSession, and call FileLoggingSession instance methods to remove channels, dispose, and perform other operations.

The FileLoggingSession class sends logged messages to disk files as they are logged. The FileLoggingSession class uses sequential logging, which means that all messages are sent to a disk file, and a sequential history of messages is retained. This is distinct from the LoggingSession class, which sends logged messages to disk on-demand, and this happens when there's a problem and the immediate history of in-memory messages is needed for analysis.

Use the FileLoggingSession class when you know that all messages need to be saved, usually over a long period of time, and when the app can't be burdened with on-demand saving steps. Like theLoggingSession class, LoggingChannel instances are added to a FileLoggingSession instance, and the FileLoggingSession instance has methods to remove channels and dispose. FileLoggingSession instances are initialized with a delegate to a new file callback, which notifies the app when a log file rollover has occurred. The feature invokes the delegate when the current internal log file has reached capacity and a new file is being created for continued sequential logging. The delegate callback can also be called at suspend boundaries, or when the FileLoggingSession is disposed.

When the delegate is invoked, the app receives an StorageFile that represents the now-closed log file. The app can forward the log file for processing in an application-defined way. After this, the session continues logging to a newly created and now-open current log file. When this log file reaches capacity, the callback delegate is invoked again for the new file, and the process repeats.

When you are done logging events, call CloseAndSaveToFileAsync in order to get the last log file since the last log file may be still open if it has not yet reached capacity.

Requirements (Windows 10 device family)

Device family


API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::Foundation::Diagnostics [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8.1 [Windows Store apps only]

Minimum supported server

Windows Server 2012 R2 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]


Windows::Foundation::Diagnostics [C++]





See also




© 2015 Microsoft