Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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.


advertisement
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#):

FileStream stream = new FileStream( "MyApplication.data", FileMode.OpenOrCreate, FileAccess.ReadWrite);

In the preceding line, MyApplication.data is a file, and the FileStream instance is a "window" into the file used for reading and writing data. You use the same general approach to create a CLFS log:

LogRecordSequence sequence = new LogRecordSequence( "DevX.CLFS.Log", FileMode.OpenOrCreate, FileAccess.ReadWrite);

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 (sequence.LogStore.Extents.Count == 0) { const long EXTENT_SIZE = 512 * 1024; sequence.LogStore.Extents.Add("Extent0", EXTENT_SIZE); sequence.LogStore.Extents.Add("Extent1"); }

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.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap