Fast and Flexible Logging with Vista's Common Log File System : Page 2

Microsoft's Common Log File System is an OS-supported logging framework that provides all the logging capabilities you needand it's available via managed code and your favorite .NET language.

by Seth Livingston

Mar 1, 2007

Page 2 of 5

Creating a CLFS Log
Creating and writing to a CLFS log is similar to creating and writing to a file using the System.IO namespace. For example, to open a file with read and write capabilities, you could write (in C#):

In this case, DevX.CLFS.Log is a log store, and the LogRecordSequence instance is a window into the log store that you use to read and write log records. CLFS automatically appends a .blf extension to the log file. You should always open the log for both reading and writing even if you only intend to write to the log, because CLFS must be able to retrieve information from the log store to operate properly. The LogRecordSequence class implements IDisposable, so be sure to call Dispose() to clean up the resources when you're done with it.

The first parameter in the LogRecordSequence constructor is the path to the log file. For example, passing in "DevX.CLFS.Log" as shown above stores the log in the same directory as the running application. Passing in a full path stores the log in the specified directory.

Log stores have to start with at least two extents, so add them the first time you create the log.

Figure 2. New Log File: The figure shows the result of creating a new CLFS log and adding two extents.

If you look at the folder where you created the logs, you can see the new DevX.CLFS.Log.blf file as well as the two new extents (see Figure 2).

Author's Note: CLFS relies on the underlying operating system and file system for security. While you can store a log file on FAT drives, to maintain full security on your CLFS logs, you should host them on Windows Server 2003 R2 or later and only on NTFS-formatted hard drives.

Before you start writing to the log, you need to establish the log policy.