Share via


The RollFileListener Trace Listener Class

DCS provides a trace listener class called Microsoft.ConnectedIndustry.ServiceModel.Common.RollFileListener in the Microsoft.ConnectedIndustry.ServiceModel.Common assembly. This trace listener implements a rolling series of trace files that lets you capture recent trace information and automatically discard older trace data. You provide property values that specify the number of trace files to use in a series, the maximum size of each file before the trace listener creates a new file, and how to format information recorded in the file. The following table summarizes these properties:

Property

Description

logDirectory

The folder to create the rolling log files in.

baseFileName

The name of the files to create. The file names are a concatenation of this property and a numeric suffix.

maxFileNumber

The maximum number of files in the series. The default value is 3. When the last file has been filled, the first file is overwritten and the file name series restarts at the beginning.

maxFileSize

The maximum size in bytes of each file in the series. The default value is 65535 (64Kb). When a file exceeds this limit, the next file in the series is created and used.

textFormatter

A string defining the format of trace messages.

The default format of messages written to the trace file is "!*{NOW};{PROCESSNAME};{PROCESSID};{THREADID};{SOURCE};{EVENTTYPE};"

This property lets you override the default format. You can include the {MESSAGE} placeholder to indicate the position of the trace message in the format, {CONTEXT} to display information about the DCS context, and {BR} to indicate a line break.

This format is used if the dontUseFormatPrefix property is set to true.

exceptionFormatter

A string defining the format of trace exception messages.

The default format is "{EXCEPTION};{MESSAGE}{BR}".

This property lets you override the default format. You can include the {EXCEPTION} placeholder to indicate the position of the trace exception message in the format, {CONTEXT} to display information about the DCS context, and {BR} to indicate a line break.

This format is used if the dontUseFormatPrefix property is set to true.

useInterProcessSynchronization

A Boolean value that indicates whether the RollFileListener class should use a mutex to synchronize access to the trace file. This enables multiple listeners to share the same trace file.

The default value is false.

dontUseFormatPrefix

A Boolean value that specifies whether the text values specified by the textFormatter and exceptionFormatter properties should be used to format trace messages and exceptions. If the value of this property is false, the default format is used.

The default value of this property is false.

enableTraceUploader

A Boolean value that indicates whether to create a marker file with the same name and sequence number as a log file but with the suffix ReadyToUpload when a log file fills and the RollFileListener switches to the next log file in sequence. An external process can monitor the log file folder for these files and upload the completed log file to an archive or other repository for safe keeping.

The default value of this property is false.

The following example shows how to configure the RollFileListener to record trace information in a series of files in the E:\Logs folder. The maximum size of each file is 10000000 bytes, and the series has a maximum of 5 files. The files are named using the value specified for the baseFileName property with a numeric suffix (WeatherService_CIS_0.LOG, WeatherService_CIS_1.LOG, and so on)

<system.diagnostics>
    <sources>
        <source name="CIS" switchValue="Error, Critical">
            <listeners>
                <add name="fileListener" type="Microsoft.ConnectedIndustry.ServiceModel.Common.RollFileListener,  Microsoft.ConnectedIndustry.ServiceModel.Common, version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" logDirectory="E:\Logs" baseFileName="WeatherService_CIS" maxFileNumber="5" maxFileSize="10000000" textFormatter="{MESSAGE}{BR}" exceptionFormatter="{EXCEPTION};{BR};{MESSAGE}{BR}{CONTEXT}{BR}" useInterProcessSyncronization="false" dontUseFormatPrefix="false" enableTraceUploader="false" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

See Also

The DCS Tracing Infrastructure

Configuring Tracing in DCS Services and Client Applications