ComponentSpace Trace Listeners Class Library Reference

CyclicFileTraceListener Class

The CyclicFileTraceListener is a trace listener that writes to a file (eg. 00000.log), until it reaches a configurable size, and then writes to the next file in the sequence (00001.log).

For a list of all members of this type, see CyclicFileTraceListener Members.

System.Object
   System.MarshalByRefObject
      System.Diagnostics.TraceListener
         ComponentSpace.TraceListeners.CyclicFileTraceListener

[Visual Basic]
Public Class CyclicFileTraceListener
    Inherits TraceListener
[C#]
public class CyclicFileTraceListener : TraceListener

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

Trace files are written to the specified directory and are named:

<DirectoryName>\<FilePrefix><SequenceNumber><FileSuffix>

Using the default properties, trace file are named .\00000.log, .\00001.log etc with each file no more then 64 kbytes.

The following is an example of configuring the trace listener using the application's XML configuration file. NB. String values may either be enclosed in "double quotation marks" or 'single quotation marks' using XML entity references where required.


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
    <trace autoflush="true" indentsize="4">
      <listeners>
        <add
          name="CyclicFileTraceListener"
          type="ComponentSpace.TraceListeners.CyclicFileTraceListener,ComponentSpace.TraceListeners"
          initializeData="directoryName='c:\logs',
                          fieldSeparator=';',
                          filePrefix='mylog',
                          fileSequenceNumber=1000,
                          fileSuffix='.txt',
                          includeCallersName=true,
                          includePidTid=true,
                          includeTimeStamp=true,
                          maxFileSize=8192,
                          maxFileCount=100"/>
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

The configuration property names and valid values are:

directoryName

directoryName is a string specifying the directory in which to write trace file eg. directoryName="c:\logs". The trace directory defaults to the current directory.


fieldSeparator

fieldSeparator is a string specifying the field separator to use in the trace entries eg. fieldSeparator=";". The default field separator is ", ".


filePrefix

filePrefix is a string specifying the prefix used to construct the file name eg. filePrefix="mylog". The default is to use no file prefix.


fileSequenceNumber

fileSequenceNumber is a number specifying the initial file sequence number eg. fileSequenceNumber=1000. The default sequence number is zero.


fileSuffix

fileSuffix is a string specifying the suffix used to construct the file name eg. fileSuffix=".txt". The default file suffix is ".log".


includeCallersName

includeCallersName is a boolean specifying whether to include the caller's class and method name in the trace entries eg. includeCallersName=true. The default is false.


includePidTid

includePidTid is a boolean specifying whether to include process and thread identifiers in the trace entries eg. includePidTid=false. The default is false.


includeTimeStamp

includeTimeStamp is a boolean specifying whether to include a timestamp in the trace entries eg. includeTimeStamp=true. The default is true.


maxFileSize

maxFileSize is a number specifying maximum file size in bytes eg. maxFileSize=8192. The file size defaults to 64 kilobytes.


maxFileCount

maxFileCount is a number specifying maximum number of files eg. maxFileCount=10. The file count defaults to an unlimited number of files.

If a maximum file count is specified then once the maximum number of files have been created then log entries will wrap around to the earliest file. For example, if log files 00000.log through to 00009.log exist and the maximum file count is 10 then entries starting at 00000.log are overwritten.


Examples

To specify the directory and maximum file size but default the other parameters: directoryName="c:\logs", maxFileSize=8192

To enable PID/TID and caller name tracing: includePidTid=true, includeCallersName=true

To modify all properties: directoryName="c:\logs", fieldSeparator=";", filePrefix="mylog", fileSequenceNumber=1000, fileSuffix=".txt", includeTimeStamp=false, includePidTid=true, includeTimeStamp=true, maxFileSize=8192, maxFileCount=10

Requirements

Namespace: ComponentSpace.TraceListeners

Assembly: ComponentSpace.TraceListeners (in ComponentSpace.TraceListeners.dll)

See Also

CyclicFileTraceListener Members | ComponentSpace.TraceListeners Namespace