Open sandboxFocus

Class LogRecordBuilder

Builds a log record (typically, but not necessarily a string) for an action. You can think of the LogRecordBuilder as a semantic StringBuilder. PostSharp emits code that invokes methods such as SetParameter<T>(int, string, ParameterKind, string, T) or SetReturnValue<T>(int, string, string, T, IFormatter<T>). The responsibility of the LogRecordBuilder is to format a record and emit it to the backend.

Inheritance
LogRecordBuilder
Namespace: PostSharp.Patterns.Diagnostics.RecordBuilders
Assembly: PostSharp.Patterns.Diagnostics.dll
Syntax
public abstract class LogRecordBuilder : ICustomLogRecordBuilder, IDisposable

Constructors

Name Description
LogRecordBuilder()

Properties

Name Description
Context

Gets the LoggingContext to which the record belongs.

CustomRecordAttributes

Gets the attributes that describe how the LogRecordBuilder is used when it builds a custom message or a custom activity.

IsDisposed

Gets a value indicating whether the current instance has been disposed.

RecordKind

Gets the kind of the current record (for example, MethodEntry or MethodException).

SyntheticId

Gets a cross-process globally unique identifier for the current LoggingContext. This value is created according to the value of the LoggingBackend.Options.SyntheticIdFormatter property.

ThreadContext

Gets the ThreadLoggingContext to which the current LogRecordBuilder belongs.

Methods

Name Description
BeginCustomRecord(LoggingContext, ref CustomLogRecordInfo)

Initializes the current LogRecordBuilder to emit a custom record.

BeginRecord(LoggingContext, ref LogRecordInfo, ref LogMemberInfo)

Initializes the current LogRecordBuilder to emit a standard (non-custom) record for a given context and method.

BeginWriteItem(CustomLogRecordItem, in CustomLogRecordTextOptions)

Begins building the specified item.

Complete()

Emits the record and resets the current LogRecordBuilder. This method is invoked after all SetThis<T>(T), SetParameter<T>(int, string, ParameterKind, string, T) and similar methods have been called.

Dispose()

Finishes the logging of the current record. Calling this method does not actually make the current LogRecordBuilder unusable, but it makes it usable for the next record in the same thread.

EmitRecord()

Emits the record. Invoked by the Complete() method.

EndWriteItem(CustomLogRecordItem)

Ends building the specified item.

ForEachProperty(LoggingPropertyVisitor<object>)

Invokes a delegate for each property defined in the current log record.

ForEachProperty<T>(LoggingPropertyVisitor<T>, ref T)

Invokes a delegate for each property defined in the current log record.

GetOutputMultiplexEventData()

Returns a list of properties that will be passed to the next backend in order if a multiplexer is used. See the remarks.

Reset()

Resets all fields and properties of the current LogRecordBuilder to their initial value. Invoked by the Complete() method.

SetException(Exception)

Sets the exception for the method or activity.

SetExecutionTime(double, bool)

Sets the method or activity execution time.

SetMethodGenericParameter<T>(int)

Not implemented.

SetParameter<T>(int, string, ParameterKind, string, T)

Sets the value of a given parameter and uses the default formatter.

SetParameter<T>(int, string, ParameterKind, string, T, IFormatter<T>)

Sets the value of a given parameter and specifies the Formatter<T>.

SetReturnValue<T>(int, string, string, T)

Sets a given return value and uses the default formatter. A method can have several return values in C# 7.0.

SetReturnValue<T>(int, string, string, T, IFormatter<T>)

Sets a given return value and uses a given formatter. A method can have several return values in C# 7.0.

SetThis<T>(T)

Sets the this (instance) value and uses the default formatter. This method is only invoked if the IncludeThisValue property is true.

SetThis<T>(T, IFormatter<T>)

Sets the this (instance) value and uses a given formatter.

SetTypeGenericParameter<T>(int)

Not implemented.

VisitProperties(Action<string, object>, in LoggingPropertyVisitorOptions)

Invokes a delegate for each property on the current log record. This offers a simple way to visit properties, but it has a performance overhead compared to VisitProperties<TState>(ILoggingPropertyVisitor<TState>, ref TState, in LoggingPropertyVisitorOptions) because it is weakly typed and causes the allocation of a closure class to build the action. It also does not expose the LoggingPropertyOptions.

VisitProperties<TState>(ILoggingPropertyVisitor<TState>, ref TState, in LoggingPropertyVisitorOptions)

Invokes the Visit<TValue>(string, TValue, in LoggingPropertyOptions, ref TState) method of an interface implementation for each property on the current record, but not in the context stack.

WriteCustomParameter<T>(int, in CharSpan, T, in CustomLogParameterOptions)

Writes a custom parameter (passed as a CharSpan) and uses the default formatter.

WriteCustomParameter<T>(int, in CharSpan, T, in CustomLogParameterOptions, IFormatter<T>)

Writes a custom parameter (passed as a CharSpan) and uses a given formatter.

WriteCustomParameter<T>(int, ArraySegment<char>, T)

Writes a custom parameter (passed as an ArraySegment<char>) and uses the default formatter.

WriteCustomParameter<T>(int, ArraySegment<char>, T, IFormatter<T>)

Writes a custom parameter (passed as an ArraySegment<char>) and uses a given formatter.

WriteCustomString(in CharSpan)

Writes a custom string that is passed as a CharSpan.

WriteCustomString(ArraySegment<char>)

Writes a custom string that is passed as an ArraySegment<char>.