Partager via


Flat File event sink

patterns & practices Developer Center

The FlatFileSink class is defined in the Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks namespace. It is included in the Semantic Logging Application Block – Text file sinks package obtainable from NuGet.

The name of the extension method used to create a sink and subscribe it to an event listener is LogToFlatFile.

The method CreateListener in the FlatFileLog class creates an observable listener and a FlatFileSink instance, and subscribes the sink to the listener.

The following table describes the parameters of the LogToFlatFile and CreateListener methods. If you are using the application block out-of-process, you set these parameters using the configuration file for the Out-of-Process Host. See Configuration schema for the out-of-process model for details.

Parameter

Description

fileName

The name of the file where entries are written. If you do not provide a filename, the sink uses a randomly generated file name. This is a required value. It can include environment variables such as %WINDIR%, %TEMP%, and %USERPROFILE%. Each sink instance should use a unique file name.

formatter

The formatter to use with this event sink. The default formatter is the EventTextFormatter. This parameter is optional.

isAsync

This optional parameter specifies if writing to the file should be done synchronously with a blocking call (false, the default) or asynchronously without blocking the UI (true). Asynchronous operation is not configurable in the out-of-process scenario.

The following table shows the information that is output by the Flat File event sink. The formatter used by the Flat File event sink determines the actual content of the messages. For more information, see Choosing and using text formatters.

Column

Description

ProviderId

A unique identifier for the event source that logged the message.

EventId

A unique identifier for this event type. This id is specified using the EventId property of the Event attribute that decorates the log method in your custom event source.

EventKeywords

An integer value that represents the value of the Keywords property of the Event attribute that decorates the log method in your custom event source. If multiple Keywords are assigned to a log method, this value represents the result of an OR of the keyword values.

Level

The value of the Level property of the Event attribute that decorates the log method in your custom event source. It can be one of Verbose, Informational, Warning, Error, Critical, or LogAlways.

Message

This is the formatted message written to the log. It is the value of the Message property of the Event attribute that decorates your log messages in your custom event source, with the placeholders replaced by values from the event payload.

Opcode

The value of the Opcode property of the Event attribute that decorates the log method in your custom event source. Valid values are defined by the EventOpcode enumeration.

Task

A task identifier. You can optionally assign task identifiers to the log messages in your custom event source by using the Task property of the Event attribute that decorates the log method in your event source.

Version

A version number. You can optionally assign a version number to the log messages in your custom event source by using the Version property of the Event attribute that decorates the log method in your event source.

ProcessId

The identifier assigned to the process where the event was raised. This value is a nullable Integer. It is available only when the application is running in full trust mode.

ThreadId

The identifier assigned to the thread that raised this event. This value is a nullable Integer. It is available only when the application is running in full trust mode.

ActivityId

A GUID identifier for the current activity in the process for which the event is involved.

RelatedActivityId

A GUID identifier for a related activity in a different process that is related to the current process.

Payload

The parameter values passed to the log method in your custom event source. These are displayed in JSON format.

Timestamp

A timestamp that records when the log message was written. The timestamp includes a UTC offset value.

Next Topic | Previous Topic | Home | Community