Table of Contents

Class AsynchronousTraceListenerWrapper

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

Trace listener that wraps a normal trace listener to perform asynchronous tracing requests.

public sealed class AsynchronousTraceListenerWrapper : TraceListener, IDisposable, IAsynchronousTraceListener
Inheritance
AsynchronousTraceListenerWrapper
Implements
Inherited Members

Remarks

When disposed, the wrapper will attempt to complete all buffered tracing requests before completing the dispose request. To change this behavior specify a value for the disposeTimeout constructor parameter other than null or InfiniteTimeSpan.

Constructors

AsynchronousTraceListenerWrapper(TraceListener, bool, int?, int?, TimeSpan?)

Initializes a new instance of the AsynchronousTraceListenerWrapper class.

public AsynchronousTraceListenerWrapper(TraceListener wrappedTraceListener, bool ownsWrappedTraceListener = true, int? bufferSize = 30000, int? maxDegreeOfParallelism = null, TimeSpan? disposeTimeout = null)

Parameters

wrappedTraceListener TraceListener

The wrapped trace listener.

ownsWrappedTraceListener bool

Indicates whether the wrapper should dispose the wrapped trace listener.

bufferSize int?

Size of the buffer for asynchronous requests.

maxDegreeOfParallelism int?

The max degree of parallelism for thread safe listeners. Specify null to use the current core count.

disposeTimeout TimeSpan?

The timeout for waiting to complete buffered requests when disposing. When null the default of InfiniteTimeSpan is used.

Properties

TraceListener

Gets the wrapped TraceListener.

public TraceListener TraceListener { get; }

Property Value

TraceListener

Methods

Close()

When overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output.

public override void Close()

Dispose(bool)

Releases the unmanaged resources used by the TraceListener and optionally releases the 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.

Fail(string)

Emits an error message to the listener you create when you implement the TraceListener class.

public override void Fail(string message)

Parameters

message string

A message to emit.

Fail(string, string)

Emits an error message and a detailed error message to the listener you create when you implement the TraceListener class.

public override void Fail(string message, string detailMessage)

Parameters

message string

A message to emit.

detailMessage string

A detailed message to emit.

Flush()

When overridden in a derived class, flushes the output buffer.

public override void Flush()

Flush(ReportTracingError)

Flushes the output buffer asynchronously.

public void Flush(ReportTracingError reportError)

Parameters

reportError ReportTracingError

The delegate to use to report errors while tracing asynchronously.

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

Writes trace information, a data object and event information to the listener specific output.

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.

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

Writes trace information, a data object and event information to the listener specific output.

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

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.

reportError ReportTracingError

The delegate to use to report errors while tracing asynchronously.

TraceData(TraceEventCache, string, TraceEventType, int, params object[])

Writes trace information, an array of data objects and event information to the listener specific output.

public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, params 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[]

An array of objects to emit as data.

TraceEvent(TraceEventCache, string, TraceEventType, int)

Writes trace and event information to the listener specific output.

public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)

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.

TraceEvent(TraceEventCache, string, TraceEventType, int, string)

Writes trace information, a message, and event information to the listener specific output.

public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)

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.

message string

A message to write.

TraceEvent(TraceEventCache, string, TraceEventType, int, string, params object[])

Writes trace information, a formatted array of objects and event information to the listener specific output.

public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)

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.

format string

A format string that contains zero or more format items, which correspond to objects in the args array.

args object[]

An object array containing zero or more objects to format.

TraceTransfer(TraceEventCache, string, int, string, Guid)

Writes trace information, a message, a related activity identity and event information to the listener specific output.

public override void TraceTransfer(TraceEventCache eventCache, string source, int id, string message, Guid relatedActivityId)

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.

id int

A numeric identifier for the event.

message string

A message to write.

relatedActivityId Guid

A Guid object identifying a related activity.

TraceTransfer(TraceEventCache, string, int, string, Guid, ReportTracingError)

Writes trace information, a message, a related activity identity and event information to the listener specific output.

public void TraceTransfer(TraceEventCache eventCache, string source, int id, string message, Guid relatedActivityId, ReportTracingError reportError)

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.

id int

A numeric identifier for the event.

message string

A message to write.

relatedActivityId Guid

A Guid object identifying a related activity.

reportError ReportTracingError

The delegate to use to report errors while tracing asynchronously.

Write(object)

Writes the value of the object's ToString() method to the listener you create when you implement the TraceListener class.

public override void Write(object o)

Parameters

o object

An object whose fully qualified class name you want to write.

Write(object, string)

Writes a category name and the value of the object's ToString() method to the listener you create when you implement the TraceListener class.

public override void Write(object o, string category)

Parameters

o object

An object whose fully qualified class name you want to write.

category string

A category name used to organize the output.

Write(string)

When overridden in a derived class, writes the specified message to the listener you create in the derived class.

public override void Write(string message)

Parameters

message string

A message to write.

Exceptions

NotImplementedException

Write(string, string)

Writes a category name and a message to the listener you create when you implement the TraceListener class.

public override void Write(string message, string category)

Parameters

message string

A message to write.

category string

A category name used to organize the output.

WriteLine(object)

Writes the value of the object's ToString() method to the listener you create when you implement the TraceListener class, followed by a line terminator.

public override void WriteLine(object o)

Parameters

o object

An object whose fully qualified class name you want to write.

WriteLine(object, string)

Writes a category name and the value of the object's ToString() method to the listener you create when you implement the TraceListener class, followed by a line terminator.

public override void WriteLine(object o, string category)

Parameters

o object

An object whose fully qualified class name you want to write.

category string

A category name used to organize the output.

WriteLine(string)

When overridden in a derived class, writes a message to the listener you create in the derived class, followed by a line terminator.

public override void WriteLine(string message)

Parameters

message string

A message to write.

Exceptions

NotImplementedException

WriteLine(string, string)

Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator.

public override void WriteLine(string message, string category)

Parameters

message string

A message to write.

category string

A category name used to organize the output.