Table of Contents

Class RollingFlatFileTraceListener

Namespace
Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners
Assembly
Microsoft.Practices.EnterpriseLibrary.Logging.dll

Performs logging to a file and rolls the output file when either time or size thresholds are exceeded.

public class RollingFlatFileTraceListener : FlatFileTraceListener, IDisposable
Inheritance
RollingFlatFileTraceListener
Implements
Inherited Members

Remarks

Logging always occurs to the configured file name, and when roll occurs a new rolled file name is calculated by adding the timestamp pattern to the configured file name.

The need of rolling is calculated before performing a logging operation, so even if the thresholds are exceeded roll will not occur until a new entry is logged.

Both time and size thresholds can be configured, and when the first threshold is reached, both will be reset.

The elapsed time is calculated from the creation date of the logging file.

Constructors

RollingFlatFileTraceListener(string, string, string, ILogFormatter, int, string, RollFileExistsBehavior, RollInterval, int)

Initializes a new instance of the RollingFlatFileTraceListener class.

public RollingFlatFileTraceListener(string fileName, string header = "----------------------------------------", string footer = "----------------------------------------", ILogFormatter formatter = null, int rollSizeKB = 0, string timeStampPattern = "yyyy-MM-dd", RollFileExistsBehavior rollFileExistsBehavior = RollFileExistsBehavior.Overwrite, RollInterval rollInterval = RollInterval.None, int maxArchivedFiles = 0)

Parameters

fileName string

The filename where the entries will be logged.

header string

The header to add before logging an entry.

footer string

The footer to add after logging an entry.

formatter ILogFormatter

The formatter.

rollSizeKB int

The maxium file size (KB) before rolling.

timeStampPattern string

The date format that will be appended to the new roll file.

rollFileExistsBehavior RollFileExistsBehavior

Expected behavior that will be used when the roll file has to be created.

rollInterval RollInterval

The time interval that makes the file rolles.

maxArchivedFiles int

The maximum number of archived files to keep.

Fields

DefaultSeparator

Represents the default separator used for headers and footers.

public const string DefaultSeparator = "----------------------------------------"

Field Value

string

Properties

RollingHelper

public RollingFlatFileTraceListener.StreamWriterRollingHelper RollingHelper { get; }

Property Value

RollingFlatFileTraceListener.StreamWriterRollingHelper

The RollingFlatFileTraceListener.StreamWriterRollingHelper for the flat file.

Methods

Dispose(bool)

Releases managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

~RollingFlatFileTraceListener()

Finalizes an instance of the RollingFlatFileTraceListener class.

protected ~RollingFlatFileTraceListener()

TraceData(TraceEventCache, string, TraceEventType, int, object)

Writes trace information, a data object and event information to the file, performing a roll if necessary.

public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)

Parameters

eventCache TraceEventCache

A TraceEventCache object that contains the current process ID, thread ID, and stack trace information.

source string

A name used to identify the output, typically the name of the application that generated the trace event.

eventType TraceEventType

One of the TraceEventType values specifying the type of event that has caused the trace.

id int

A numeric identifier for the event.

data object

The trace data to emit.