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
timestampDateTimeOffsetThe time at which the event occurred.
levelLogEventLevelThe level of the event.
exceptionExceptionAn exception associated with the event, or null.
messageTemplateMessageTemplateThe message template describing the event.
propertiesIEnumerable<LogEventProperty>Properties associated with the event, including those presented in
messageTemplate.
Exceptions
- ArgumentNullException
When
messageTemplateisnull- ArgumentNullException
When
propertiesisnull
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
timestampDateTimeOffsetThe time at which the event occurred.
levelLogEventLevelThe level of the event.
exceptionExceptionAn exception associated with the event, or null.
messageTemplateMessageTemplateThe message template describing the event.
propertiesIEnumerable<LogEventProperty>Properties associated with the event, including those presented in
messageTemplate.traceIdActivityTraceIdThe id of the trace that was active when the event was created, if any.
spanIdActivitySpanIdThe id of the span that was active when the event was created, if any.
Exceptions
- ArgumentNullException
When
messageTemplateisnull- ArgumentNullException
When
propertiesisnull
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
propertyLogEventPropertyThe property to add or update.
Exceptions
- ArgumentNullException
When
propertyisnull
AddPropertyIfAbsent(LogEventProperty)
Add a property to the event if not already present.
public void AddPropertyIfAbsent(LogEventProperty property)
Parameters
propertyLogEventPropertyThe property to add.
Exceptions
- ArgumentNullException
When
propertyisnull
RemovePropertyIfPresent(string)
Remove a property from the event, if present. Otherwise no action is performed.
public void RemovePropertyIfPresent(string propertyName)
Parameters
propertyNamestringThe 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
formatProviderIFormatProviderSupplies 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
outputTextWriterThe output.
formatProviderIFormatProviderSupplies 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
timestampDateTimeOffsetThe time at which the event occurred.
levelLogEventLevelThe level of the event.
exceptionExceptionAn exception associated with the event, or null.
messageTemplateMessageTemplateThe message template describing the event.
propertiesDictionary<string, LogEventPropertyValue>Properties associated with the event, including those presented in
messageTemplate.traceIdActivityTraceIdThe id of the trace that was active when the event was created, if any.
spanIdActivitySpanIdThe 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
messageTemplateisnull- ArgumentNullException
When
propertiesisnull