RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


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

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.

Establishing a CLFS Log Policy
A CLFS log policy is a collection of settings that determine the characteristics and automatic behavior of your log. The LogPolicy class encapsulates three categories of policy settings: automatic growth, extent management, and tail pinning. You manage automatic growth via log policy properties (see Table 1).

Table 1: The table shows the log policy properties that affect automatic log growth or shrinkage.
Type Property Description
bool LogPolicy.AutoGrow Set this property to true to allow CLFS to automatically increase the size of your log when needed. The default value is false.
int LogPolicy.AutoShrinkPercentage When the amount of unused log store space is greater than the percentage specified in this property, CLFS will remove extents to save disk space. The default value is zero.
PolicyUnit LogPolicy.GrowthRate This property determines how much additional space CLFS allocates when your log store is full and needs to grow. You can specify the growth rate in extent units or percentage units. The default value is one extent.

You manage the extents via log policy settings as well (see Table 2).

Table 2: The table shows the extent management properties.
Type Property Description
int LogPolicy.MaximumExtentCount Use this property to cap the size of your log, taking the size of your extents and the available disk space on the target machine into account. Set this property to zero to allow for unlimited extents. The default value is zero.
int LogPolicy.MinimumExtentCount Use this property to set the lower bound for the size of your log. CLFS logs require at least two extents. The default value is two.
string LogPolicy.NewExtentPrefix Set this property to the full path and file name prefix for automatically created extents. The default value is "Container."
int LogPolicy.NextExtentSuffix When CLFS creates new extents, it creates a file name by concatenating LogPolicy.NewExtentPrefix and LogPolicy.NextExtentSuffix. The default value is zero.

I'll cover an additional property, the LogPolicy.TailPinnedThreshold and the LogPolicy.TailPinned event later in this article.

Author's Note: You have to set the log policy every time you create a LogRecordSequence. CLFS doesn't save the policy settings because they apply to a particular stream's LogRecordSequence rather than the log.

   sequence.LogStore.Policy.AutoGrow = true;
   sequence.LogStore.Policy.AutoShrinkPercentage = 25;
   sequence.LogStore.Policy.GrowthRate = new PolicyUnit(
      2, PolicyUnitType.Extents);
   sequence.LogStore.Policy.MaximumExtentCount = 50;
   sequence.LogStore.Policy.MinimumExtentCount = 2;
   sequence.LogStore.Policy.NewExtentPrefix = EXTENT_NAME;
   sequence.LogStore.Policy.NextExtentSuffix = sequence.LogStore.Extents.Count;
Note the last line in the preceding code. The policy settings don't take effect until you call the LogPolicy.Commit method.

Now you're ready to start writing to the log.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date