Share via


Console event sink

patterns & practices Developer Center

The Console event sink is useful during development and testing because you can easily see the trace messages as they appear. However, the console sink is not appropriate for use in a production environment.

The ConsoleSink class is defined in the Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks namespace. It is included in the main Semantic Logging Application Block package obtainable from NuGet.

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

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

The following table describes the parameters of the LogToConsole 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

formatter

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

colorMapper

The color mapper to use with this event sink. The default color mapper class is the DefaultConsoleColorMapper. This parameter is optional.

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

Field

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.

EventName

The name of this event.

Keywords

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.

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.

Timestamp

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

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.

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.

Payload

The parameter values passed to the log method in your custom event source. These are displayed using JSON format. Any custom log methods that have no parameters will display “{}”.

Next Topic | Previous Topic | Home | Community