Class LogEvent
A log event.
public class LogEvent
- Inheritance
-
LogEvent
- Inherited Members
Constructors
LogEvent(DateTimeOffset, LogEventLevel, Exception?, MessageTemplate, IEnumerable<LogEventProperty>)
Construct a new LogEvent.
public LogEvent(DateTimeOffset timestamp, LogEventLevel level, Exception? exception, MessageTemplate messageTemplate, IEnumerable<LogEventProperty> properties)
Parameters
timestamp
DateTimeOffsetThe time at which the event occurred.
level
LogEventLevelThe level of the event.
exception
ExceptionAn exception associated with the event, or null.
messageTemplate
MessageTemplateThe message template describing the event.
properties
IEnumerable<LogEventProperty>Properties associated with the event, including those presented in
messageTemplate
.
Exceptions
- ArgumentNullException
When
messageTemplate
isnull
- ArgumentNullException
When
properties
isnull
LogEvent(DateTimeOffset, LogEventLevel, Exception?, MessageTemplate, IEnumerable<LogEventProperty>, ActivityTraceId, ActivitySpanId)
Construct a new LogEvent.
[CLSCompliant(false)]
public LogEvent(DateTimeOffset timestamp, LogEventLevel level, Exception? exception, MessageTemplate messageTemplate, IEnumerable<LogEventProperty> properties, ActivityTraceId traceId, ActivitySpanId spanId)
Parameters
timestamp
DateTimeOffsetThe time at which the event occurred.
level
LogEventLevelThe level of the event.
exception
ExceptionAn exception associated with the event, or null.
messageTemplate
MessageTemplateThe message template describing the event.
properties
IEnumerable<LogEventProperty>Properties associated with the event, including those presented in
messageTemplate
.traceId
ActivityTraceIdThe id of the trace that was active when the event was created, if any.
spanId
ActivitySpanIdThe id of the span that was active when the event was created, if any.
Exceptions
- ArgumentNullException
When
messageTemplate
isnull
- ArgumentNullException
When
properties
isnull
Properties
Exception
An exception associated with the event, or null.
public Exception? Exception { get; }
Property Value
Level
The level of the event.
public LogEventLevel Level { get; }
Property Value
MessageTemplate
The message template describing the event.
public MessageTemplate MessageTemplate { get; }
Property Value
Properties
Properties associated with the event, including those presented in MessageTemplate.
public IReadOnlyDictionary<string, LogEventPropertyValue> Properties { get; }
Property Value
SpanId
The id of the span that was active when the event was created, if any.
[CLSCompliant(false)]
public ActivitySpanId? SpanId { get; }
Property Value
Timestamp
The time at which the event occurred.
public DateTimeOffset Timestamp { get; }
Property Value
TraceId
The id of the trace that was active when the event was created, if any.
[CLSCompliant(false)]
public ActivityTraceId? TraceId { get; }
Property Value
Methods
AddOrUpdateProperty(LogEventProperty)
Add a property to the event if not already present, otherwise, update its value.
public void AddOrUpdateProperty(LogEventProperty property)
Parameters
property
LogEventPropertyThe property to add or update.
Exceptions
- ArgumentNullException
When
property
isnull
AddPropertyIfAbsent(LogEventProperty)
Add a property to the event if not already present.
public void AddPropertyIfAbsent(LogEventProperty property)
Parameters
property
LogEventPropertyThe property to add.
Exceptions
- ArgumentNullException
When
property
isnull
RemovePropertyIfPresent(string)
Remove a property from the event, if present. Otherwise no action is performed.
public void RemovePropertyIfPresent(string propertyName)
Parameters
propertyName
stringThe name of the property to remove.
RenderMessage(IFormatProvider?)
Render the message template given the properties associated with the event, and return the result.
public string RenderMessage(IFormatProvider? formatProvider = null)
Parameters
formatProvider
IFormatProviderSupplies culture-specific formatting information, or null.
Returns
RenderMessage(TextWriter, IFormatProvider?)
Render the message template to the specified output, given the properties associated with the event.
public void RenderMessage(TextWriter output, IFormatProvider? formatProvider = null)
Parameters
output
TextWriterThe output.
formatProvider
IFormatProviderSupplies culture-specific formatting information, or null.
UnstableAssembleFromParts(DateTimeOffset, LogEventLevel, Exception?, MessageTemplate, Dictionary<string, LogEventPropertyValue>, ActivityTraceId, ActivitySpanId)
Construct a LogEvent using pre-allocated values for internal fields. Normally, the LogEvent constructor allocates a dictionary to back Properties, so that this is not unexpectedly shared. This is unnecessary in many integration scenarios, leading to an additional nontrivial Dictionary<TKey, TValue> allocation. This method allows specialized callers to avoid that overhead.
[CLSCompliant(false)]
public static LogEvent UnstableAssembleFromParts(DateTimeOffset timestamp, LogEventLevel level, Exception? exception, MessageTemplate messageTemplate, Dictionary<string, LogEventPropertyValue> properties, ActivityTraceId traceId, ActivitySpanId spanId)
Parameters
timestamp
DateTimeOffsetThe time at which the event occurred.
level
LogEventLevelThe level of the event.
exception
ExceptionAn exception associated with the event, or null.
messageTemplate
MessageTemplateThe message template describing the event.
properties
Dictionary<string, LogEventPropertyValue>Properties associated with the event, including those presented in
messageTemplate
.traceId
ActivityTraceIdThe id of the trace that was active when the event was created, if any.
spanId
ActivitySpanIdThe id of the span that was active when the event was created, if any.
Returns
Remarks
Because this method exposes parameters that essentially map 1:1 with internal fields of LogEvent, the parameter list may change across major Serilog versions.
Exceptions
- ArgumentNullException
When
messageTemplate
isnull
- ArgumentNullException
When
properties
isnull